ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-09-07 04:59:20
Exec Total Coverage
Lines: 3107 8715 35.7%
Functions: 84 304 27.6%
Branches: 2695 7699 35.0%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "base/md5.h"
33 #include "hero_tiles.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include "iter.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern uint8_t ViewLayer3BG, ViewLayer2BG;
59 extern int32_t LayerDitherBG, LayerDitherSz;
60 extern bool NoHighlightLayer0;
61
62 using std::string;
63 using std::pair;
64
65 #define COLOR_SOLID vc(4)
66 #define COLOR_SLOPE vc(13)
67 #define COLOR_LADDER vc(6)
68 //#define COLOR_EFFECT vc(10)
69
70 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
71 extern char msgbuf[MSG_NEW_SIZE*8];
72
73 extern string zScript;
74
75 12 zmap Map;
76 int32_t prv_mode=0;
77
78 bool save_warn=true;
79
80 int32_t COMBOPOS(int32_t x, int32_t y)
81 {
82 return (((y) & 0xF0) + ((x) >> 4));
83 }
84 int32_t COMBOPOS_B(int32_t x, int32_t y)
85 {
86 if(unsigned(x) >= 256 || unsigned(y) >= 176)
87 return -1;
88 return COMBOPOS(x,y);
89 }
90 int32_t COMBOX(int32_t pos)
91 {
92 return ((pos) % 16 * 16);
93 }
94 int32_t COMBOY(int32_t pos)
95 {
96 return ((pos) & 0xF0);
97 }
98
99 void reset_dmap(int32_t index)
100 {
101 bound(index,0,MAXDMAPS-1);
102 DMaps[index].clear();
103 DMaps[index].title = "";
104 sprintf(DMaps[index].intro, " ");
105 }
106
107 void reset_dmaps()
108 {
109 for(int32_t i=0; i<MAXDMAPS; i++)
110 reset_dmap(i);
111 }
112
113 void truncate_dmap_title(std::string& title)
114 {
115 title.resize(21, ' ');
116 }
117
118 mapscr* zmap::get_prvscr()
119 {
120 return &prvscr;
121 }
122
123
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 23 times.
138 zmap::zmap()
124 {
125 23 can_paste=false;
126 23 prv_cmbcycle=0;
127 23 prv_advance=0;
128 23 prv_freeze=0;
129 23 copyffc=-1;
130
131 23 memset(scrpos, 0, sizeof(scrpos));
132 23 memset(scrview, 0, sizeof(scrview));
133 23 screens=NULL;
134 23 prv_time=0;
135 23 prv_scr=0;
136 23 prv_map=0;
137 23 copyscr=0;
138 23 cursor={};
139 copymap=0;
140 layer_target_map = 0;
141 layer_target_scr = 0;
142 layer_target_multiple = 0;
143 }
144
145 11 void zmap::clear()
146 {
147
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
148 11 }
149 void zmap::force_refr_pointer()
150 {
151 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
152 screens = nullptr;
153 else screens = &TheMaps[cursor.map*MAPSCRS];
154 }
155 bool zmap::CanUndo()
156 {
157 return undo_stack.size() > 0;
158 }
159 bool zmap::CanRedo()
160 {
161 return redo_stack.size() > 0;
162 }
163 bool zmap::CanPaste()
164 {
165 return can_paste;
166 }
167 int32_t zmap::CopyScr()
168 {
169 return (copymap<<8)+copyscr;
170 }
171 int32_t zmap::getCopyFFC()
172 {
173 return copyffc;
174 }
175 set_ffc_command::data_t zmap::getCopyFFCData()
176 {
177 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
178 }
179 67 int32_t zmap::getMapCount()
180 {
181 67 return map_count;
182 }
183 int32_t zmap::getLayerTargetMap()
184 {
185 return layer_target_map;
186 }
187 int32_t zmap::getLayerTargetScr()
188 {
189 return layer_target_scr;
190 }
191 int32_t zmap::getLayerTargetMultiple()
192 {
193 return layer_target_multiple;
194 }
195 bool zmap::isDungeon(int32_t scr)
196 {
197 for(int32_t i=0; i<4; i++)
198 {
199 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
200 {
201 return false;
202 }
203 }
204
205 return true;
206 }
207
208 bool zmap::clearall(bool validate)
209 {
210 Color=0;
211 char tbuf[10];
212
213 if((header.templatepath[0]!=0)&&validate)
214 {
215 if(!valid_zqt(header.templatepath))
216 {
217 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
218 return false;
219 }
220 }
221
222 for(int32_t i=0; i<map_count; i++)
223 {
224 setCurrMap(i);
225 sprintf(tbuf, "%d", i);
226 clearmap(true);
227 }
228
229 setCurrMap(0);
230 return true;
231 }
232
233 bool zmap::reset_templates(bool validate)
234 {
235 //why are we doing this?
236 if(colordata==NULL)
237 {
238 return false;
239 }
240
241 //int32_t ret;
242 word version, build, dummy, sversion=0;
243 byte dummyc;
244 word dummyw;
245 //int32_t section_size;
246 word temp_map_count;
247 mapscr temp_mapscr;
248 PACKFILE *f=NULL;
249
250 // setPackfilePassword(datapwd);
251 f=open_quest_template(&header, "modules/classic/default.qst", validate);
252 get_version_and_build(f, &version, &build);
253
254 if(!find_section(f, ID_MAPS))
255 {
256 // setPackfilePassword(NULL);
257 return false;
258 }
259
260 //section version info
261 if(!p_igetw(&sversion,f))
262 {
263 return false;
264 }
265
266 if(!p_igetw(&dummy,f))
267 {
268 return false;
269 }
270
271 //section size
272 dword dummy_size;
273 if(!p_igetl(&dummy_size,f))
274 {
275 return false;
276 }
277
278 //finally... section data
279 if(!p_igetw(&temp_map_count,f))
280 {
281 return false;
282 }
283
284 if(version>12)
285 {
286 if(!p_getc(&dummyc,f))
287 return qe_invalid;
288
289 if(!p_getc(&dummyc,f))
290 return qe_invalid;
291
292 if(!p_igetw(&dummyw,f))
293 return qe_invalid;
294
295 if(!p_igetw(&dummyw,f))
296 return qe_invalid;
297
298 if(!p_igetw(&dummyw,f))
299 return qe_invalid;
300
301 if(!p_igetw(&dummyw,f))
302 return qe_invalid;
303
304 if(!p_igetw(&dummyw,f))
305 return qe_invalid;
306
307 if(!p_igetw(&dummyw,f))
308 return qe_invalid;
309
310 if(!p_igetw(&dummyw,f))
311 return qe_invalid;
312
313 if(!p_igetw(&dummyw,f))
314 return qe_invalid;
315
316 if(!p_igetw(&dummyw,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_getc(&dummyc,f))
323 return qe_invalid;
324
325 if(!p_getc(&dummyc,f))
326 return qe_invalid;
327 }
328
329 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
330 {
331 readmapscreen(f, &header, &temp_mapscr, sversion);
332 }
333
334 readmapscreen(f, &header, &TheMaps[128], sversion);
335 readmapscreen(f, &header, &TheMaps[129], sversion);
336
337 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
338 {
339 readmapscreen(f, &header, &temp_mapscr, sversion);
340 }
341
342 if(version>12)
343 {
344 if(!p_getc(&dummyc,f))
345 return qe_invalid;
346
347 if(!p_getc(&dummyc,f))
348 return qe_invalid;
349
350 if(!p_igetw(&dummyw,f))
351 return qe_invalid;
352
353 if(!p_igetw(&dummyw,f))
354 return qe_invalid;
355
356 if(!p_igetw(&dummyw,f))
357 return qe_invalid;
358
359 if(!p_igetw(&dummyw,f))
360 return qe_invalid;
361
362 if(!p_igetw(&dummyw,f))
363 return qe_invalid;
364
365 if(!p_igetw(&dummyw,f))
366 return qe_invalid;
367
368 if(!p_igetw(&dummyw,f))
369 return qe_invalid;
370
371 if(!p_igetw(&dummyw,f))
372 return qe_invalid;
373
374 if(!p_igetw(&dummyw,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_getc(&dummyc,f))
381 return qe_invalid;
382
383 if(!p_getc(&dummyc,f))
384 return qe_invalid;
385 }
386
387 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
388 {
389 readmapscreen(f, &header, &temp_mapscr, sversion);
390 }
391
392 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
393 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
394
395 pack_fclose(f);
396 clear_quest_tmpfile();
397
398 return true;
399 }
400
401 bool zmap::clearmap(bool newquest)
402 {
403 if(cursor.map<map_count)
404 {
405 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
406 {
407 clearscr(i);
408 }
409
410 setCurrScr(0);
411
412 if(newquest)
413 {
414 if(!reset_templates(false))
415 {
416 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
417 }
418 }
419 }
420
421 return true;
422 }
423
424 MapCursor zmap::getCursor() const
425 {
426 return cursor;
427 }
428
429 void zmap::setCursor(MapCursor new_cursor)
430 {
431 if (cursor == new_cursor)
432 return;
433
434 if (!screens) Color = -1;
435
436 cursor = new_cursor;
437
438 refresh_color();
439
440 reset_combo_animations2();
441 mmap_mark_dirty();
442 regions_mark_dirty();
443 refresh(rALL);
444 }
445
446 bool zmap::isValidPosition(ComboPosition pos) const
447 {
448 return pos.is_valid(cursor);
449 }
450
451 int zmap::getScreenForPosition(ComboPosition pos) const
452 {
453 return cursor.viewscr + pos.screen_offset();
454 }
455
456 mapscr* zmap::CurrScr()
457 {
458 return screens+cursor.screen;
459 }
460 mapscr* zmap::Scr(int32_t scr)
461 {
462 return screens+scr;
463 }
464 mapscr* zmap::Scr(ComboPosition pos)
465 {
466 if (!pos.is_valid(cursor))
467 return nullptr;
468
469 int screen_offset = pos.screen_offset();
470 int screen = cursor.viewscr + screen_offset;
471 return AbsoluteScr(cursor.map, screen);
472 }
473 mapscr* zmap::Scr(ComboPosition pos, int layer)
474 {
475 int map = cursor.map;
476 int screen = cursor.viewscr + pos.screen_offset();
477 if (layer)
478 {
479 mapscr* scr = Map.AbsoluteScr(map, screen);
480 map = scr->layermap[CurrentLayer-1]-1;
481 screen = scr->layerscreen[CurrentLayer-1];
482 }
483
484 return AbsoluteScr(map, screen);
485 }
486 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
487 {
488 mapscr* scr = Scr(pos, layer);
489 if (scr && !(scr->valid&mVALID))
490 {
491 scr->valid |= mVALID;
492 setcolor(Color, scr);
493 }
494 return scr;
495 }
496 mapscr* zmap::AbsoluteScr(int32_t scr)
497 {
498 if(unsigned(scr) >= MAPSCRS*getMapCount())
499 return nullptr;
500 return &TheMaps[scr];
501 }
502 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
503 {
504 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
505 return nullptr;
506 return AbsoluteScr((map*MAPSCRS)+scr);
507 }
508 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
509 {
510 mapscr* scr = AbsoluteScr(map, screen);
511 if (scr && !(scr->valid&mVALID))
512 {
513 scr->valid |= mVALID;
514 setcolor(Color, scr);
515 }
516 return scr;
517 }
518 void zmap::set_prvscr(int32_t map, int32_t scr)
519 {
520 prvscr = *get_canonical_scr(map, scr);
521
522 for(int32_t i=0; i<6; i++)
523 {
524 if(prvscr.layermap[i]>0)
525 {
526 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
527 }
528 else
529 prvlayers[i].valid = 0;
530 }
531
532 prv_map=map;
533 prv_scr=scr;
534 }
535 92 int32_t zmap::getCurrMap()
536 {
537 92 return cursor.map;
538 }
539 22 void zmap::regions_mark_dirty()
540 {
541 22 regions_dirty = true;
542 22 }
543 void zmap::regions_refresh()
544 {
545 if (!regions_dirty)
546 return;
547
548 regions_dirty = false;
549 region_descriptions.clear();
550
551 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
552 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
553 region_descriptions.clear();
554 }
555 const std::vector<region_description>& zmap::get_region_descriptions()
556 {
557 regions_refresh();
558 return region_descriptions;
559 }
560 bool zmap::is_region(int screen)
561 {
562 if (screen < 0 || screen >= 128)
563 return false;
564
565 regions_refresh();
566 return current_map_region_ids[screen];
567 }
568 bool zmap::isDark(int scr)
569 {
570 return (screens[scr].flags&fDARK)!=0;
571 }
572 bool zmap::isValid(int32_t scr)
573 {
574 return (screens[scr].valid&mVALID)!=0;
575 }
576 bool zmap::isValid(int32_t map, int32_t scr)
577 {
578 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
579 }
580
581 11 void zmap::setCurrMap(int32_t index)
582 {
583
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
584 11 scrpos[cursor.map] = cursor.screen;
585 11 scrview[cursor.map] = cursor.viewscr;
586 11 cursor.map = bound(index,0,map_count);
587 11 screens = &TheMaps[cursor.map*MAPSCRS];
588
589 11 cursor.viewscr = scrview[cursor.map];
590 11 cursor.setScreen(scrpos[cursor.map]);
591
592 11 refresh_color();
593
594 11 reset_combo_animations2();
595 11 mmap_mark_dirty();
596 11 regions_mark_dirty();
597 11 }
598
599 20 int32_t zmap::getCurrScr()
600 {
601 20 return cursor.screen;
602 }
603 11 void zmap::setCurrScr(int32_t scr)
604 {
605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (scr == cursor.screen)
606 return;
607
608 11 cursor.setScreen(scr);
609
610 11 refresh_color();
611
612 11 reset_combo_animations2();
613 11 setlayertarget();
614 11 mmap_mark_dirty();
615 11 regions_mark_dirty();
616 11 }
617
618 int32_t zmap::getViewScr()
619 {
620 return cursor.viewscr;
621 }
622
623 11 void zmap::setViewSize(int32_t size)
624 {
625 11 cursor.setSize(size);
626 11 }
627
628 8 int32_t zmap::getViewSize()
629 {
630 8 return cursor.size;
631 }
632
633 11 void zmap::setlayertarget()
634 {
635 11 layer_target_map = 0;
636 11 layer_target_multiple = 0;
637
638
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
639 {
640
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
641 {
642 7616 int32_t i=(m*MAPSCRS+s);
643 7616 mapscr *ts=&TheMaps[i];
644
645 // Search through each layer
646
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
647 {
648
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 45679 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
649 {
650 if(layer_target_map > 0)
651 {
652 layer_target_multiple += 1;
653 continue;
654 }
655
656 layer_target_map = m+1;
657 layer_target_scr = s;
658 }
659 45696 }
660 7616 }
661 56 }
662 11 }
663
664 22 void zmap::refresh_color()
665 {
666 22 auto color = getcolor();
667
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 21 times.
22 if (Color != color)
668 {
669 21 loadlvlpal(color);
670 21 rebuild_trans_table();
671 21 }
672 22 }
673
674 void zmap::setcolor(int color, mapscr* scr)
675 {
676 if (!scr)
677 scr = CurrScr();
678 scr->valid |= mVALID;
679 scr->color = color;
680
681 refresh_color();
682
683 mmap_mark_dirty();
684 }
685
686 22 int32_t zmap::getcolor()
687 {
688
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 mapscr& scr = prv_mode ? prvscr : screens[cursor.screen];
689
690
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 4 times.
22 if (scr.valid & mVALID)
691 18 return scr.color;
692
693 4 return map_infos[cursor.map].autopalette;
694 22 }
695
696 void zmap::resetflags()
697 {
698 byte *di=&(screens[cursor.screen].valid);
699
700 for(int32_t i=1; i<48; i++)
701 {
702 *(di+i)=0;
703 }
704 }
705
706 word zmap::tcmbdat(int32_t pos)
707 {
708 return screens[TEMPLATE].data[pos];
709 }
710
711 word zmap::tcmbcset(int32_t pos)
712 {
713 return screens[TEMPLATE].cset[pos];
714 }
715
716 int32_t zmap::tcmbflag(int32_t pos)
717 {
718 return screens[TEMPLATE].sflag[pos];
719 }
720
721 word zmap::tcmbdat2(int32_t pos)
722 {
723 return screens[TEMPLATE2].data[pos];
724 }
725
726 word zmap::tcmbcset2(int32_t pos)
727 {
728 return screens[TEMPLATE2].cset[pos];
729 }
730
731 int32_t zmap::tcmbflag2(int32_t pos)
732 {
733 return screens[TEMPLATE2].sflag[pos];
734 }
735
736 void zmap::TemplateAll()
737 {
738 StartListCommand();
739 for(int32_t i=0; i<128; i++)
740 {
741 if((screens[i].valid&mVALID) && isDungeon(i))
742 DoTemplateCommand(-1, -1, i);
743 }
744 FinishListCommand();
745 }
746
747 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
748 {
749 if(scr==TEMPLATE)
750 return;
751
752 if(!(screens[scr].valid&mVALID))
753 screens[scr].color=Color;
754
755 screens[scr].valid|=mVALID;
756
757 for(int32_t i=0; i<32; i++)
758 {
759 screens[scr].data[i]=screens[TEMPLATE].data[i];
760 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
761 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
762 }
763
764 for(int32_t i=144; i<176; i++)
765 {
766 screens[scr].data[i]=screens[TEMPLATE].data[i];
767 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
768 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
769 }
770
771 for(int32_t y=2; y<=9; y++)
772 {
773 int32_t j=y<<4;
774 screens[scr].data[j]=screens[TEMPLATE].data[j];
775 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
776 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
777 ++j;
778 screens[scr].data[j]=screens[TEMPLATE].data[j];
779 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
780 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
781 ++j;
782 j+=12;
783 screens[scr].data[j]=screens[TEMPLATE].data[j];
784 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
785 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
786 ++j;
787 screens[scr].data[j]=screens[TEMPLATE].data[j];
788 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
789
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 }
793
794 if(floorcombo!=-1)
795 {
796 for(int32_t y=2; y<9; y++)
797 for(int32_t x=2; x<14; x++)
798 {
799 int32_t i=(y<<4)+x;
800 screens[scr].data[i] = floorcombo;
801 screens[scr].cset[i] = floorcset;
802 }
803 }
804
805 for(int32_t i=0; i<4; i++)
806 putdoor(scr,i,screens[scr].door[i]);
807 }
808
809
810 void zmap::clearscr(int32_t scr)
811 {
812 screens[scr].zero_memory();
813 screens[scr].valid=mVERSION;
814 auto const& mapinf = map_infos[cursor.map];
815 for(int q = 0; q < 6; ++q)
816 {
817 auto layer = mapinf.autolayers[q];
818 screens[scr].layermap[q] = layer;
819 screens[scr].layerscreen[q] = layer ? scr : 0;
820 }
821 screens[scr].color = mapinf.autopalette;
822 if (scr == cursor.screen)
823 refresh_color();
824 mmap_mark_dirty();
825 }
826
827 const char *loaderror[] =
828 {
829
830 "OK","File not found","Incomplete data",
831 "Invalid version","Invalid file"
832
833 };
834
835 int32_t zmap::load(const char *path)
836 {
837 PACKFILE *f=pack_fopen_password(path,F_READ, "");
838
839 if(!f)
840 return 1;
841
842
843 int16_t version;
844 byte build;
845
846 //get the version
847 if(!p_igetw(&version,f))
848 {
849 goto file_error;
850 }
851
852 //get the build
853 if(!p_getc(&build,f))
854 {
855 goto file_error;
856 }
857
858 for(int32_t i=0; i<MAPSCRS; i++)
859 {
860 mapscr tmpimportscr;
861 tmpimportscr.zero_memory();
862 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
863 {
864 al_trace("failed zmap::load\n");
865 goto file_error;
866 }
867
868 switch(ImportMapBias)
869 {
870 case 0:
871 *(screens+i) = tmpimportscr;
872 break;
873
874 case 1:
875 if(!(screens[i].valid&mVALID))
876 {
877 *(screens+i) = tmpimportscr;
878 }
879 break;
880
881 case 2:
882 if(tmpimportscr.valid&mVALID)
883 {
884 *(screens+i) = tmpimportscr;
885 }
886 break;
887 }
888 }
889
890
891 pack_fclose(f);
892
893 setCurrScr(0);
894 mmap_mark_dirty();
895 regions_mark_dirty();
896 return 0;
897
898 file_error:
899 pack_fclose(f);
900 clearmap(false);
901 return 2;
902 }
903
904 int32_t zmap::save(const char *path)
905 {
906 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
907
908 if(!f)
909 return 1;
910
911 if(!p_iputw(V_MAPS,f))
912 {
913 pack_fclose(f);
914 return 3;
915 }
916
917 // This was the "build number", but that's totally useless here. Keep this junk byte
918 // so as not to totally break exports between ZC versions.
919 if(!p_putc(0,f))
920 {
921 pack_fclose(f);
922 return 3;
923 }
924
925 for(int32_t i=0; i<MAPSCRS; i++)
926 {
927 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
928 {
929 pack_fclose(f);
930 return 2;
931 }
932 }
933
934 pack_fclose(f);
935 return 0;
936 }
937
938
939 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
940 {
941 // Hookshots can be blocked by solid combos on all 3 ground layers.
942 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
943
944 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
945 return true;
946 if (c->walk&(1<<i))
947 return false;
948
949 for(int32_t k=0; k<2; k++)
950 {
951 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
952
953 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
954 {
955 return false;
956 }
957 }
958
959 return true;
960 }
961
962 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
963 {
964 // Hookshots can be blocked by solid combos on all 3 ground layers.
965 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
966
967 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
968 return true;
969 if (c->walk&(1<<i))
970 return false;
971
972 for(int32_t k=0; k<2; k++)
973 {
974 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
975
976 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
977 {
978 return false;
979 }
980 }
981
982 return true;
983 }
984
985 bool zmap::isstepable(int32_t combo)
986 {
987 // This is kind of odd but it's true to the engine (see maps.cpp)
988 return (combo_class_buf[combobuf[combo].type].ladder_pass);
989 }
990
991 // Returns the letter of the warp combo.
992 int32_t zmap::warpindex(int32_t combo)
993 {
994 switch(combobuf[combo].type)
995 {
996 case cCAVE:
997 case cPIT:
998 case cSTAIR:
999 case cCAVE2:
1000 case cSWIMWARP:
1001 case cDIVEWARP:
1002 case cSWARPA:
1003 return 0;
1004
1005 case cCAVEB:
1006 case cPITB:
1007 case cSTAIRB:
1008 case cCAVE2B:
1009 case cSWIMWARPB:
1010 case cDIVEWARPB:
1011 case cSWARPB:
1012 return 1;
1013
1014 case cCAVEC:
1015 case cPITC:
1016 case cSTAIRC:
1017 case cCAVE2C:
1018 case cSWIMWARPC:
1019 case cDIVEWARPC:
1020 case cSWARPC:
1021 return 2;
1022
1023 case cCAVED:
1024 case cPITD:
1025 case cSTAIRD:
1026 case cCAVE2D:
1027 case cSWIMWARPD:
1028 case cDIVEWARPD:
1029 case cSWARPD:
1030 return 3;
1031
1032 case cPITR:
1033 case cSTAIRR:
1034 case cSWARPR:
1035 return 4;
1036 }
1037
1038 return -1;
1039
1040 }
1041
1042 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1043 {
1044 if(top)
1045 line(dest,x,y,x+15,y,c);
1046 rectfill(dest,x,y,x+3,y+15,c);
1047 rectfill(dest,x+12,y,x+15,y+15,c);
1048 rectfill(dest,x+4,y+2,x+11,y+5,c);
1049 rectfill(dest,x+4,y+10,x+11,y+13,c);
1050 }
1051
1052 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1053 {
1054 line(dest,x,y,x+15,y,c);
1055 }
1056
1057 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1058 {
1059 int32_t cx = COMBOX(pos);
1060 int32_t cy = COMBOY(pos);
1061
1062 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1063
1064 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1065
1066 int32_t bridgedetected = 0;
1067
1068 for(int32_t i=0; i<4; i++)
1069 {
1070 int32_t tx=((i&2)<<2)+x;
1071 int32_t ty=((i&1)<<3)+y;
1072 int32_t tx2=((i&2)<<2)+cx;
1073 int32_t ty2=((i&1)<<3)+cy;
1074 for (int32_t m = layer; m <= 1; m++)
1075 {
1076 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1077 {
1078 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1079 {
1080 bridgedetected |= (1<<i);
1081 }
1082 }
1083 else
1084 {
1085 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1086 {
1087 bridgedetected |= (1<<i);
1088 }
1089 }
1090 }
1091 if (bridgedetected & (1<<i))
1092 {
1093 if (i >= 3) break;
1094 else continue;
1095 }
1096 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1097 {
1098 for(int32_t k=0; k<8; k+=2)
1099 for(int32_t j=0; j<8; j+=2)
1100 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1101 }
1102 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1103 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1104
1105 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1106 {
1107 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1108 {
1109 for(int32_t k=0; k<8; k+=2)
1110 for(int32_t j=0; j<8; j+=2)
1111 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1112 }
1113 else
1114 {
1115 int32_t color = COLOR_SOLID;
1116
1117 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1118 color=vc(6);
1119 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1120 color=vc(7);
1121
1122 rectfill(dest,tx,ty,tx+7,ty+7,color);
1123 }
1124 }
1125 }
1126
1127 bridgedetected = 0;
1128 for(int32_t i=0; i<4; i++)
1129 {
1130 int32_t tx2=((i&2)<<2)+cx;
1131 int32_t ty2=((i&1)<<3)+cy;
1132 for (int32_t m = 0; m <= 1; m++)
1133 {
1134 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1135 {
1136 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1137 {
1138 bridgedetected |= (1<<i);
1139 }
1140 }
1141 else
1142 {
1143 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1144 {
1145 bridgedetected |= (1<<i);
1146 }
1147 }
1148 }
1149 }
1150
1151 // Draw damage combos
1152 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1153 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1154 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1155 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1156 || combo_class_buf[c1.type].modify_hp_amount
1157 || combo_class_buf[c2.type].modify_hp_amount;
1158
1159 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1160
1161 if(dmg)
1162 {
1163 if (bridgedetected <= 0)
1164 {
1165 for(int32_t k=0; k<16; k+=2)
1166 for(int32_t j=0; j<16; j+=2)
1167 if(((k+j)/2)%2)
1168 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1169 }
1170 else
1171 {
1172 for(int32_t i=0; i<4; i++)
1173 {
1174 if (!(bridgedetected & (1<<i)))
1175 {
1176 int32_t tx=((i&2)<<2)+x;
1177 int32_t ty=((i&1)<<3)+y;
1178 for(int32_t k=0; k<8; k+=2)
1179 for(int32_t j=0; j<8; j+=2)
1180 if(((k+j)/2)%2)
1181 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1182 }
1183 }
1184 }
1185 }
1186
1187 if(c.type == cSLOPE)
1188 {
1189 slope_info s(c, x, y);
1190 s.draw(dest, 0, 0, COLOR_SLOPE);
1191 }
1192 auto fl0 = MAPFLAG2(-1,cx,cy);
1193 auto fl1 = MAPFLAG2(0,cx,cy);
1194 auto fl2 = MAPFLAG2(1,cx,cy);
1195 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1196 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1197 {
1198 bool top = false;
1199 if(cy)
1200 {
1201 top = true;
1202 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1203 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1204 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1205 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1206 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1207 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1208 {
1209 top = false;
1210 }
1211 }
1212 draw_ladder(dest,x,y,COLOR_LADDER,top);
1213 }
1214 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1215 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1216 {
1217 draw_platform(dest,x,y,COLOR_LADDER);
1218 }
1219 }
1220
1221 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1222 {
1223 int32_t cx = COMBOX(pos);
1224 int32_t cy = COMBOY(pos);
1225
1226 if (screen < 0) return;
1227 if (map < 0) return;
1228
1229 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1230
1231 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1232
1233 int32_t bridgedetected = 0;
1234 for(int32_t i=0; i<4; i++)
1235 {
1236 int32_t tx=((i&2)<<2)+x;
1237 int32_t ty=((i&1)<<3)+y;
1238 int32_t tx2=((i&2)<<2)+cx;
1239 int32_t ty2=((i&1)<<3)+cy;
1240 for (int32_t m = layer; m <= 1; m++)
1241 {
1242 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1243 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1244 {
1245 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1246 {
1247 bridgedetected |= (1<<i);
1248 }
1249 }
1250 else
1251 {
1252 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1253 {
1254 bridgedetected |= (1<<i);
1255 }
1256 }
1257 }
1258 if (bridgedetected & (1<<i))
1259 {
1260 continue;
1261 }
1262 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1263 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1264
1265
1266 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1267 {
1268 for(int32_t k=0; k<8; k+=2)
1269 for(int32_t j=0; j<8; j+=2)
1270 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1271 }
1272 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1273 {
1274 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1275 {
1276 for(int32_t k=0; k<8; k+=2)
1277 for(int32_t j=0; j<8; j+=2)
1278 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1279 }
1280 else
1281 {
1282 int32_t color = COLOR_SOLID;
1283
1284 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1285 color=vc(6);
1286 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1287 color=vc(7);
1288
1289 rectfill(dest,tx,ty,tx+7,ty+7,color);
1290 }
1291 }
1292 }
1293
1294 bridgedetected = 0;
1295 for(int32_t i=0; i<4; i++)
1296 {
1297 int32_t tx2=((i&2)<<2)+cx;
1298 int32_t ty2=((i&1)<<3)+cy;
1299 for (int32_t m = 0; m <= 1; m++)
1300 {
1301 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1302 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1303 {
1304 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1305 {
1306 bridgedetected |= (1<<i);
1307 }
1308 }
1309 else
1310 {
1311 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1312 {
1313 bridgedetected |= (1<<i);
1314 }
1315 }
1316 }
1317 }
1318
1319 // Draw damage combos
1320 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1321 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1322 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1323 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1324 || combo_class_buf[c1.type].modify_hp_amount
1325 || combo_class_buf[c2.type].modify_hp_amount;
1326
1327 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1328
1329 if(dmg)
1330 {
1331 if (bridgedetected <= 0)
1332 {
1333 for(int32_t k=0; k<16; k+=2)
1334 for(int32_t j=0; j<16; j+=2)
1335 if(((k+j)/2)%2)
1336 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1337 }
1338 else
1339 {
1340 for(int32_t i=0; i<4; i++)
1341 {
1342 if (!(bridgedetected & (1<<i)))
1343 {
1344 int32_t tx=((i&2)<<2)+x;
1345 int32_t ty=((i&1)<<3)+y;
1346 for(int32_t k=0; k<8; k+=2)
1347 for(int32_t j=0; j<8; j+=2)
1348 if(((k+j)/2)%2)
1349 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1350 }
1351 }
1352 }
1353 }
1354
1355 if(c.type == cSLOPE)
1356 {
1357 slope_info s(c, x, y);
1358 s.draw(dest, 0, 0, COLOR_SLOPE);
1359 }
1360 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1361 auto fl1 = MAPFLAG3(map,screen,0,pos);
1362 auto fl2 = MAPFLAG3(map,screen,1,pos);
1363 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1364 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1365 {
1366 bool top = false;
1367 if(cy)
1368 {
1369 top = true;
1370 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1371 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1372 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1373 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1374 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1375 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1376 {
1377 top = false;
1378 }
1379 }
1380 draw_ladder(dest,x,y,COLOR_LADDER,top);
1381 }
1382 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1383 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1384 {
1385 draw_platform(dest,x,y,COLOR_LADDER);
1386 }
1387 }
1388
1389 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1390 {
1391 const newcombo& c = combobuf[cmbdat];
1392
1393 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1394
1395 for(int32_t i=0; i<4; i++)
1396 {
1397 int32_t tx=((i&2)<<2)+x;
1398 int32_t ty=((i&1)<<3)+y;
1399
1400 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1401 {
1402 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1403 {
1404 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1405 }
1406 else
1407 {
1408 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1409 }
1410 }
1411
1412
1413 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1414 {
1415 for(int32_t k=0; k<8; k+=2)
1416 for(int32_t j=0; j<8; j+=2)
1417 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1418 }
1419 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1420 {
1421 if(c.type==cLADDERHOOKSHOT)
1422 {
1423 for(int32_t k=0; k<8; k+=2)
1424 for(int32_t j=0; j<8; j+=2)
1425 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1426 }
1427 else
1428 {
1429 int32_t color = COLOR_SOLID;
1430
1431 if(c.type==cLADDERONLY)
1432 color=vc(6);
1433 else if(c.type==cHOOKSHOTONLY)
1434 color=vc(7);
1435
1436 rectfill(dest,tx,ty,tx+7,ty+7,color);
1437 }
1438 }
1439
1440 // Draw damage combos
1441 if(combo_class_buf[c.type].modify_hp_amount != 0)
1442 {
1443 for(int32_t k=0; k<8; k+=2)
1444 for(int32_t j=0; j<8; j+=2)
1445 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1446 }
1447 }
1448
1449 if(c.type == cSLOPE)
1450 {
1451 slope_info s(c, 0, 0);
1452 zfix const& slope = s.slope();
1453
1454 BITMAP* sub = create_bitmap_ex(8,16,16);
1455 clear_bitmap(sub);
1456 s.draw(sub, 0, 0, COLOR_SLOPE);
1457 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1458 destroy_bitmap(sub);
1459 }
1460 if(c.flag == mfSIDEVIEWLADDER)
1461 {
1462 draw_ladder(dest,x,y,COLOR_LADDER);
1463 }
1464 else if(c.flag == mfSIDEVIEWPLATFORM)
1465 {
1466 draw_platform(dest,x,y,COLOR_LADDER);
1467 }
1468 }
1469
1470 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1471 {
1472 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1473 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1474 }
1475 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1476 {
1477
1478 newcombo const& c = combobuf[cmbdat];
1479
1480 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1481 {
1482 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1483 // text_mode(-1);
1484 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1485 if(sflag)
1486 {
1487 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1488 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1489 }
1490
1491 if(c.flag)
1492 {
1493 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1494 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1495 }
1496 }
1497
1498 if(flags&cCSET)
1499 {
1500 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1501 // text_mode(inv?vc(15):vc(0));
1502 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1503 }
1504 else if(flags&cCTYPE)
1505 {
1506 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1507 // text_mode(inv?vc(15):vc(0));
1508 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1509 }
1510 }
1511
1512 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1513 {
1514 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1515
1516 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1517 if(repos)
1518 {
1519 combotile_override_x = x+(8*(scale-1));
1520 combotile_override_y = y+(8*(scale-1));
1521 }
1522 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1523 if(repos) combotile_override_x = combotile_override_y = -1;
1524 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1525 destroy_bitmap(b);
1526 }
1527 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1528 {
1529 static newcombo nilcombo;
1530 nilcombo.tile = 0;
1531
1532 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1533
1534 if(c.tile==0)
1535 {
1536 rectfill(dest,x,y,x+15,y+15,vc(0));
1537 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1538 return;
1539 }
1540
1541 putcombo(dest,x,y,cmbdat,cset);
1542
1543 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1544 {
1545 if(sflag)
1546 {
1547 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1548 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1549 }
1550
1551 if(combobuf[cmbdat].flag)
1552 {
1553 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1554 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1555 }
1556 }
1557
1558 if(flags&cWALK)
1559 {
1560 put_walkflags(dest,x,y,cmbdat,0);
1561 }
1562
1563 if(flags&cCSET)
1564 {
1565 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1566 // text_mode(inv?vc(15):vc(0));
1567 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1568 }
1569 else if(flags&cCTYPE)
1570 {
1571 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1572 // text_mode(inv?vc(15):vc(0));
1573 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1574 }
1575 }
1576 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1577 {
1578 auto blitx = 1 + (slot % 16) * 17;
1579 auto blity = 1 + (slot / 16) * 17;
1580 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1581 }
1582
1583
1584 void copy_mapscr(mapscr *dest, const mapscr *src)
1585 {
1586 if(!dest || !src) return;
1587 *dest = *src;
1588 }
1589
1590 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1591 {
1592 int32_t x=0,y=0;
1593 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1594
1595 switch(side)
1596 {
1597 case up:
1598 case down:
1599 x=((pos&15)<<4)+xofs;
1600 y=(ignorepos?0:(pos&0xF0))+yofs;
1601 break;
1602
1603 case left:
1604 case right:
1605 x=(ignorepos?0:((pos&15)<<4))+xofs;
1606 y=(pos&0xF0)+yofs;
1607 break;
1608 }
1609
1610 switch(type)
1611 {
1612 case dt_lock:
1613 case dt_shut:
1614 case dt_boss:
1615 case dt_bomb:
1616 switch(side)
1617 {
1618 case up:
1619 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1620 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1621 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1622 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1623 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1624 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1625 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1626 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1627 break;
1628
1629 case down:
1630 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1631 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1632 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1633 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1634 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1635 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1636 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1637 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1638 break;
1639
1640 case left:
1641 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1642 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1643 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1644 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1645 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1646 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1647
1648 if(x+16 >= dest->w)
1649 break;
1650
1651 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1653 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1655 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1656 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1657 break;
1658
1659 case right:
1660
1661 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1663 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1665 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1666 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1667
1668 if(x+16 <= 0)
1669 break;
1670
1671 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1673 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1675 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1676 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1677 break;
1678 }
1679
1680 break;
1681
1682 case dt_pass:
1683 case dt_wall:
1684 case dt_walk:
1685 default:
1686 break;
1687 }
1688 }
1689
1690 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1691 {
1692 int32_t x=((pos&15)<<4)+xofs;
1693 int32_t y=(pos&0xF0)+yofs;
1694 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1695
1696
1697 switch(side)
1698 {
1699 case up:
1700 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1701 {
1702 overcombo(dest,x,y,
1703 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1705 }
1706
1707 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1708 {
1709 overcombo(dest,x+16,y,
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1711
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1713 }
1714
1715 break;
1716
1717 case down:
1718 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1719 {
1720 overcombo(dest,x,y,
1721 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1723 }
1724
1725 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1726 {
1727 overcombo(dest,x+16,y,
1728 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1730 }
1731
1732 break;
1733
1734 case left:
1735 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1736 {
1737 overcombo(dest,x,y,
1738 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1740 }
1741
1742 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1743 {
1744 overcombo(dest,x,y+16,
1745 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1747 }
1748
1749 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1750 {
1751 overcombo(dest,x,y+32,
1752 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1754 }
1755
1756 break;
1757
1758 case right:
1759 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1760 {
1761 overcombo(dest,x,y,
1762 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1764 }
1765
1766 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1767 {
1768 overcombo(dest,x,y+16,
1769
1770 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1772 }
1773
1774 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1775 {
1776 overcombo(dest,x,y+32,
1777 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1779 }
1780
1781 break;
1782 }
1783 }
1784
1785 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1786 {
1787 word cmbcheck1, cmbcheck2;
1788 newcombo combocheck1, combocheck2;
1789 combocheck1 = combobuf[0];
1790 combocheck2 = combobuf[0];
1791 combocheck1.walk = 0;
1792 combocheck2.walk = 0;
1793
1794 int32_t layermap, layerscreen;
1795
1796 switch(dir)
1797 {
1798 case up:
1799 {
1800 if(i>15) //not top row of combos
1801 {
1802 return false;
1803 }
1804
1805 if(screen<16) //top row of screens
1806 {
1807 return false;
1808
1809 }
1810
1811 //check main screen
1812 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1813 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1814 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1815 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1816
1817 //check layer 1
1818 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1819
1820 if(layermap>-1 && layermap<map_count)
1821 {
1822 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1823 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1824 if (combobuf[cmbcheck1].type == cBRIDGE)
1825 {
1826 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1827 {
1828 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1829 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1830 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1831 }
1832 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1833 }
1834 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1835 }
1836
1837 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1838
1839 if(layermap>-1 && layermap<map_count)
1840 {
1841 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1842 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1843 if (combobuf[cmbcheck2].type == cBRIDGE)
1844 {
1845 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1846 {
1847 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1848 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1849 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1850 }
1851 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1852 }
1853 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1854 }
1855
1856 //check layer 2
1857 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1858
1859 if(layermap>-1 && layermap<map_count)
1860 {
1861 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1862
1863 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1864 if (combobuf[cmbcheck2].type == cBRIDGE)
1865 {
1866 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1867 {
1868 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1869 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1870 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1871 }
1872 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1873 }
1874 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1875 }
1876
1877 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1878
1879 if(layermap>-1 && layermap<map_count)
1880 {
1881 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1882 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1883 if (combobuf[cmbcheck2].type == cBRIDGE)
1884 {
1885 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1886 {
1887 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1888 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1889 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1890 }
1891 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1892 }
1893 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1894 }
1895
1896 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1897 {
1898 return true;
1899 }
1900
1901 break;
1902 }
1903 case down:
1904 {
1905 if(i<160) //not bottom row of combos
1906 {
1907 return false;
1908 }
1909
1910 if(screen>111) //bottom row of screens
1911 {
1912 return false;
1913 }
1914
1915 //check main screen
1916 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1917 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1918 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1919 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1920
1921
1922 //check layer 1
1923 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1924
1925 if(layermap>-1 && layermap<map_count)
1926 {
1927 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1928 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1929 if (combobuf[cmbcheck1].type == cBRIDGE)
1930 {
1931 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1932 {
1933 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1934 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1935 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1936 }
1937 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1938 }
1939 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1940 }
1941
1942 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1943
1944 if(layermap>-1 && layermap<map_count)
1945 {
1946 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1947 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1948 if (combobuf[cmbcheck2].type == cBRIDGE)
1949 {
1950 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1951 {
1952 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1953 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1954 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1955 }
1956 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1957 }
1958 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1959 }
1960
1961 //check layer 2
1962 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1963
1964 if(layermap>-1 && layermap<map_count)
1965 {
1966 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1967 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1968 if (combobuf[cmbcheck1].type == cBRIDGE)
1969 {
1970 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1971 {
1972 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1973 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1974 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1975 }
1976 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1977 }
1978 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1979 }
1980
1981 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1982
1983 if(layermap>-1 && layermap<map_count)
1984 {
1985 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1986 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1987 if (combobuf[cmbcheck2].type == cBRIDGE)
1988 {
1989 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1990 {
1991 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1992 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1993 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1994 }
1995 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1996 }
1997 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1998 }
1999
2000 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2001 {
2002 return true;
2003 }
2004
2005 break;
2006 }
2007 case left:
2008 {
2009 if((i&0xF)!=0) //not left column of combos
2010 {
2011 return false;
2012 }
2013
2014 if((screen&0xF)==0) //left column of screens
2015 {
2016 return false;
2017 }
2018
2019 //check main screen
2020 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2021 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2022 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2023 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2024
2025 //check layer 1
2026 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2027
2028 if(layermap>-1 && layermap<map_count)
2029 {
2030 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2031 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2032 if (combobuf[cmbcheck1].type == cBRIDGE)
2033 {
2034 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2035 {
2036 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2037 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2038 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2039 }
2040 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2041 }
2042 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2043 }
2044
2045 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2046
2047 if(layermap>-1 && layermap<map_count)
2048 {
2049 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2050 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2051 if (combobuf[cmbcheck2].type == cBRIDGE)
2052 {
2053 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2054 {
2055 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2056 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2057 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2058 }
2059 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2060 }
2061 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2062 }
2063
2064 //check layer 2
2065 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2066
2067 if(layermap>-1 && layermap<map_count)
2068 {
2069 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2070 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2071 if (combobuf[cmbcheck1].type == cBRIDGE)
2072 {
2073 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2074 {
2075 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2076 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2077 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2078 }
2079 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2080 }
2081 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2082 }
2083
2084 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2085
2086 if(layermap>-1 && layermap<map_count)
2087 {
2088 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2089 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2090 if (combobuf[cmbcheck2].type == cBRIDGE)
2091 {
2092 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2093 {
2094 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2095 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2096 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2097 }
2098 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2099 }
2100 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2101 }
2102
2103 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2104 {
2105 return true;
2106 }
2107
2108 break;
2109 }
2110 case right:
2111 {
2112 if((i&0xF)!=15) //not right column of combos
2113 {
2114 return false;
2115 }
2116
2117 if((screen&0xF)==15) //right column of screens
2118 {
2119 return false;
2120 }
2121
2122 //check main screen
2123 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2124 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2125 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2126 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2127
2128 //check layer 1
2129 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2130
2131 if(layermap>-1 && layermap<map_count)
2132 {
2133 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2134 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2135 if (combobuf[cmbcheck1].type == cBRIDGE)
2136 {
2137 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2138 {
2139 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2140 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2141 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2142 }
2143 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2144 }
2145 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2146 }
2147
2148 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2149
2150 if(layermap>-1 && layermap<map_count)
2151 {
2152 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2153 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2154 if (combobuf[cmbcheck2].type == cBRIDGE)
2155 {
2156 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2157 {
2158 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2159 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2160 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2161 }
2162 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2163 }
2164 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2165 }
2166
2167 //check layer 2
2168 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2169
2170 if(layermap>-1 && layermap<map_count)
2171 {
2172 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2173 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2174 if (combobuf[cmbcheck1].type == cBRIDGE)
2175 {
2176 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2177 {
2178 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2179 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2180 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2181 }
2182 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2183 }
2184 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2185 }
2186
2187 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2188
2189 if(layermap>-1 && layermap<map_count)
2190 {
2191 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2192
2193 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2194 if (combobuf[cmbcheck2].type == cBRIDGE)
2195 {
2196 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2197 {
2198 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2199 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2200 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2201 }
2202 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2203 }
2204 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2205 }
2206
2207 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2208 {
2209 return true;
2210 }
2211
2212 break;
2213 }
2214 }
2215
2216 return false;
2217 }
2218
2219 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2220 {
2221 int32_t checkcombo;
2222
2223 if(alignment_arrow_timer>31)
2224 {
2225 if(scr<0)
2226 {
2227 scr=cursor.screen;
2228 }
2229
2230 if((scr<128)) //do the misalignment arrows
2231 {
2232 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2233 {
2234 if(misaligned(cursor.map, scr, checkcombo, up))
2235 {
2236 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2237 }
2238 }
2239
2240 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2241 {
2242 if(misaligned(cursor.map, scr, checkcombo, down))
2243 {
2244 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 }
2246 }
2247
2248 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2249 {
2250 if(misaligned(cursor.map, scr, checkcombo, left))
2251 {
2252 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 }
2254 }
2255
2256 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2257 {
2258 if(misaligned(cursor.map, scr, checkcombo, right))
2259 {
2260 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2261 }
2262 }
2263
2264 int32_t tempalign;
2265
2266 //check top left corner
2267 checkcombo=0;
2268 tempalign=0;
2269 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2270 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2271
2272 switch(tempalign)
2273 {
2274 case 0:
2275 break;
2276
2277 case 1: //up
2278 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2279 break;
2280
2281 case 2: //left
2282 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2283 break;
2284
2285 case 3: //up-left
2286 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2287 break;
2288 }
2289
2290 //check top right corner
2291 checkcombo=15;
2292 tempalign=0;
2293 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2294 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2295
2296 switch(tempalign)
2297 {
2298 case 0:
2299 break;
2300
2301 case 1: //up
2302 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2303 break;
2304
2305 case 2: //right
2306 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2307 break;
2308
2309 case 3: //up-right
2310 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2311 break;
2312 }
2313
2314 //check bottom left corner
2315 checkcombo=160;
2316 tempalign=0;
2317 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2318 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2319
2320 switch(tempalign)
2321 {
2322 case 0:
2323 break;
2324
2325 case 1: //down
2326 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2327 break;
2328
2329 case 2: //left
2330 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2331 break;
2332
2333 case 3: //down-left
2334 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2335 break;
2336 }
2337
2338 //check bottom right corner
2339
2340 checkcombo=175;
2341 tempalign=0;
2342 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2343 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2344
2345 switch(tempalign)
2346 {
2347 case 0:
2348 break;
2349
2350 case 1: //down
2351 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2352 break;
2353
2354 case 2: //right
2355 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2356 break;
2357
2358 case 3: //down-right
2359 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2360 break;
2361 }
2362 }
2363 }
2364 }
2365
2366 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2367 {
2368 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2369 }
2370
2371 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2372 {
2373 if (map < 0 || screen < 0) return 0;
2374
2375 if(pos>175 || pos < 0)
2376 return 0;
2377
2378 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2379
2380 if (!m->is_valid()) return 0;
2381
2382 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2383
2384 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2385
2386 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2387
2388 if (!scr->is_valid()) return 0;
2389
2390 return scr->data[pos]; // entire combo code
2391 }
2392
2393 // Takes array index layer num., not actual layer num.
2394 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2395 {
2396 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2397
2398 if(map<0)
2399 map=cursor.map;
2400
2401 if(scr<0)
2402 scr=cursor.screen;
2403
2404 mapscr *screen1;
2405
2406 if(prv_mode)
2407 {
2408 screen1=get_prvscr();
2409 }
2410 else
2411 {
2412 screen1=AbsoluteScr(cursor.map,cursor.screen);
2413 }
2414
2415 int32_t layermap;
2416 layermap=screen1->layermap[lyr]-1;
2417
2418 if(layermap<0 || layermap >= map_count) return 0;
2419
2420 mapscr *layer;
2421
2422 if(prv_mode)
2423 layer = &prvlayers[lyr];
2424 else
2425 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2426
2427 int32_t pos = COMBOPOS(x,y);
2428
2429 if(pos>175 || pos < 0)
2430 return 0;
2431
2432 return layer->data[pos];
2433 }
2434
2435 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2436 {
2437 if(map<0)
2438 map=cursor.map;
2439
2440 if(scr<0)
2441 scr=cursor.screen;
2442
2443 mapscr *screen1;
2444
2445 if(prv_mode)
2446 {
2447 screen1=get_prvscr();
2448 }
2449 else
2450 {
2451 screen1=AbsoluteScr(cursor.map,cursor.screen);
2452 }
2453
2454 x = vbound(x, 0, 16*16);
2455 y = vbound(y, 0, 11*16);
2456 int32_t combo = COMBOPOS(x,y);
2457
2458 if(combo>175 || combo < 0)
2459 return 0;
2460
2461 return screen1->data[combo];
2462 }
2463
2464 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2465 {
2466 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2467 }
2468
2469 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2470 {
2471 if (map < 0 || screen < 0) return 0;
2472
2473 if(pos>175 || pos < 0)
2474 return 0;
2475
2476 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2477
2478 if (!m->is_valid()) return 0;
2479
2480 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2481
2482 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2483
2484 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2485
2486 if (!scr->is_valid()) return 0;
2487
2488 return scr->sflag[pos]; // entire combo code
2489 }
2490
2491 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2492 {
2493 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2494
2495 if(map<0)
2496 map=cursor.map;
2497
2498 if(scr<0)
2499 scr=cursor.screen;
2500
2501 mapscr *screen1;
2502
2503 if(prv_mode)
2504 {
2505 screen1=get_prvscr();
2506 }
2507 else
2508 {
2509 screen1=AbsoluteScr(cursor.map,cursor.screen);
2510 }
2511
2512 int32_t layermap;
2513 layermap=screen1->layermap[lyr]-1;
2514
2515 if(layermap<0 || layermap >= map_count) return 0;
2516
2517 mapscr *layer;
2518
2519 if(prv_mode)
2520 layer = &prvlayers[lyr];
2521 else
2522 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2523
2524 int32_t combo = COMBOPOS(x,y);
2525
2526 if(combo>175 || combo < 0)
2527 return 0;
2528
2529 return layer->sflag[combo];
2530 }
2531
2532 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2533 {
2534 if(map<0)
2535 map=cursor.map;
2536
2537 if(scr<0)
2538 scr=cursor.screen;
2539
2540 mapscr *screen1;
2541
2542 if(prv_mode)
2543 {
2544 screen1=get_prvscr();
2545 }
2546 else
2547 {
2548 screen1=AbsoluteScr(cursor.map,cursor.screen);
2549 }
2550
2551 x = vbound(x, 0, 16*16);
2552 y = vbound(y, 0, 11*16);
2553 int32_t combo = COMBOPOS(x,y);
2554
2555 if(combo>175 || combo < 0)
2556 return 0;
2557
2558 return screen1->sflag[combo];
2559 }
2560
2561 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2562 {
2563 mapscr *layers[7];
2564 mapscr *basescr;
2565 if(prv_mode)
2566 {
2567 layers[0] = &prvscr;
2568 basescr = layers[0];
2569 for(auto q = 1; q < 7; ++q)
2570 {
2571 if(prvlayers[q-1].valid)
2572 layers[q] = &(prvlayers[q-1]);
2573 else layers[q] = NULL;
2574 }
2575 }
2576 else
2577 {
2578 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2579 basescr = layers[0];
2580 for(auto q = 1; q < 7; ++q)
2581 {
2582 int32_t lmap = basescr->layermap[q-1]-1;
2583 int32_t lscr = basescr->layerscreen[q-1];
2584 if(lmap < 0)
2585 layers[q] = NULL;
2586 else layers[q] = AbsoluteScr(lmap, lscr);
2587 }
2588 }
2589 for(auto q = 0; q < 7; ++q)
2590 {
2591 if(!layers[q]) continue;
2592 for(auto pos = 0; pos < 176; ++pos)
2593 {
2594 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2595 if(cmb.type == cTORCH)
2596 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2597 }
2598 }
2599 word maxffc = basescr->numFFC();
2600 for(auto q = 0; q < maxffc; ++q)
2601 {
2602 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2603 if(cmb.type == cTORCH)
2604 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2605 }
2606 }
2607
2608 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2609 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2610 {
2611 newcombo const& cmb = combobuf[cid];
2612 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2613 if(dither)
2614 {
2615 if (LayerDitherSz == 0)
2616 return;
2617 BITMAP* buf = create_bitmap_ex(8,16,16);
2618 clear_bitmap(buf);
2619 overcombo(buf,0,0,cid,cset);
2620 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2621 if(over)
2622 {
2623 if(transp)
2624 {
2625 color_map = &trans_table2;
2626 draw_trans_sprite(dest, buf, x, y);
2627 color_map = &trans_table;
2628 }
2629 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2630 }
2631 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2632 destroy_bitmap(buf);
2633 }
2634 else if(over)
2635 {
2636 if(transp)
2637 overcombotranslucent(dest,x,y,cid,cset,0);
2638 else overcombo(dest,x,y,cid,cset);
2639 }
2640 else put_combo(dest,x,y,cid,cset,flags,sflag);
2641 }
2642 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2643 {
2644 if(!md) return;
2645 for (int32_t i = 0; i < 176; i++)
2646 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2647 }
2648 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2649 {
2650 if(!md) return;
2651 for (int32_t i = 0; i < 176; i++)
2652 {
2653 int data = md->data[i];
2654 if(combo_class_buf[combobuf[data].type].overhead)
2655 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2656 }
2657 }
2658 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2659 {
2660 if(!LayerMaskInt[lyr])
2661 return nullptr;
2662 if(lyr == 0)
2663 return basescr;
2664 int layermap = basescr->layermap[lyr-1]-1;
2665
2666 if(layermap>-1 && layermap<map_count)
2667 {
2668 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2669 return &TheMaps[layerscreen];
2670 }
2671 return nullptr;
2672 }
2673 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2674 {
2675 int num_ffcs = basescr->numFFC();
2676 for(int32_t i=num_ffcs-1; i>=0; i--)
2677 {
2678 auto const& ff = basescr->ffcs[i];
2679 if(ff.data)
2680 {
2681 if(!(ff.flags&ffc_changer))
2682 {
2683 int32_t tx=(ff.x.getInt())+x;
2684 int32_t ty=(ff.y.getInt())+y;
2685
2686 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2687 {
2688 if(ff.flags&ffc_trans)
2689 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2690 else
2691 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2692 }
2693 }
2694 }
2695 }
2696 }
2697 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2698 {
2699 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2700 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2701
2702 if(map<0)
2703 map=cursor.map;
2704
2705 if(screen<0)
2706 screen=cursor.screen;
2707
2708 mapscr *basescr;
2709 mapscr* layers[7] = {nullptr};
2710
2711 if(prv_mode)
2712 {
2713 hl_layer = -1;
2714 basescr=get_prvscr();
2715 }
2716 else
2717 {
2718 basescr=AbsoluteScr(map,screen);
2719 }
2720 layers[0] = _zmap_get_lyr_checked(0,basescr);
2721 for(int lyr = 1; lyr < 7; ++lyr)
2722 {
2723 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2724 : _zmap_get_lyr_checked(lyr,basescr);
2725 }
2726
2727 if(!(basescr->valid&mVALID))
2728 {
2729 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2730 rectfill(dest,x,y,x+255,y+175,vc(1));
2731
2732 if(ShowMisalignments)
2733 {
2734 check_alignments(dest,x,y,screen);
2735 }
2736
2737 return;
2738 }
2739
2740 if(LayerMaskInt[0]==0)
2741 {
2742 byte bgfill = 0;
2743 if (LayerDitherBG > -1)
2744 bgfill = vc(LayerDitherBG);
2745 rectfill(dest,x,y,x+255,y+175,bgfill);
2746 }
2747
2748 if(get_qr(qr_CLASSIC_DRAWING_ORDER))
2749 {
2750 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2751 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2752 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2753 }
2754
2755 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2756 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2757 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2758
2759 if(!get_qr(qr_CLASSIC_DRAWING_ORDER))
2760 {
2761 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2762 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2763 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2764 }
2765
2766 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !get_qr(qr_CLASSIC_DRAWING_ORDER) || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2767 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2768
2769
2770 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2771 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2772
2773 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2774 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2775 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2776
2777 int32_t doortype[4];
2778
2779 for(int32_t i=0; i<4; i++)
2780 {
2781 switch(basescr->door[i])
2782 {
2783 case dOPEN:
2784 doortype[i]=dt_pass;
2785 break;
2786
2787 case dLOCKED:
2788 doortype[i]=dt_lock;
2789 break;
2790
2791 case d1WAYSHUTTER:
2792 case dSHUTTER:
2793 doortype[i]=dt_shut;
2794 break;
2795
2796 case dBOSS:
2797 doortype[i]=dt_boss;
2798 break;
2799
2800 case dBOMB:
2801 doortype[i]=dt_bomb;
2802 break;
2803 }
2804 }
2805
2806 switch(basescr->door[up])
2807 {
2808 case dBOMB:
2809 over_door(dest,39,up,x,y,false, screen);
2810 [[fallthrough]];
2811 case dOPEN:
2812 case dLOCKED:
2813 case d1WAYSHUTTER:
2814 case dSHUTTER:
2815 case dBOSS:
2816 put_door(dest,7,up,doortype[up],x,y,false,screen);
2817 break;
2818
2819 case dWALK:
2820 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2821 {
2822 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2823 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2824 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2825 }
2826 else
2827
2828 {
2829 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2830 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2831 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2832 }
2833
2834 break;
2835 }
2836
2837 switch(basescr->door[down])
2838 {
2839 case dBOMB:
2840 over_door(dest,135,down,x,y,false,screen);
2841 [[fallthrough]];
2842 case dOPEN:
2843 case dLOCKED:
2844 case d1WAYSHUTTER:
2845 case dSHUTTER:
2846 case dBOSS:
2847 put_door(dest,151,down,doortype[down],x,y,false,screen);
2848 break;
2849
2850 case dWALK:
2851 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2852 {
2853 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2854 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2855 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2856 }
2857 else
2858 {
2859 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2860 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2861 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2862 }
2863
2864 break;
2865 }
2866
2867 switch(basescr->door[left])
2868 {
2869 case dBOMB:
2870 over_door(dest,66,left,x,y,false,screen);
2871 [[fallthrough]];
2872 case dOPEN:
2873 case dLOCKED:
2874 case d1WAYSHUTTER:
2875 case dSHUTTER:
2876 case dBOSS:
2877 put_door(dest,64,left,doortype[left],x,y,false,screen);
2878 break;
2879
2880 case dWALK:
2881 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2882 {
2883 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2884 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2885 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2886 }
2887 else
2888 {
2889 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2890 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2891 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2892 }
2893
2894 break;
2895 }
2896
2897 switch(basescr->door[right])
2898 {
2899
2900 case dBOMB:
2901 over_door(dest,77,right,x,y,false,screen);
2902 [[fallthrough]];
2903 case dOPEN:
2904 case dLOCKED:
2905 case d1WAYSHUTTER:
2906 case dSHUTTER:
2907 case dBOSS:
2908 put_door(dest,78,right,doortype[right],x,y,false,screen);
2909 break;
2910
2911 case dWALK:
2912 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2913 {
2914 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2915 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2916 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2917 }
2918 else
2919 {
2920 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2921 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2922 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2923 }
2924
2925 break;
2926 }
2927
2928 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2929 {
2930 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2931 }
2932
2933 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2934 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2935 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2936
2937 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2938 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2939
2940 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2941
2942 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2943 {
2944 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2945 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2946 }
2947 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2948 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2949
2950 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2951
2952 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2953 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2954 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2955
2956 int num_ffcs = basescr->numFFC();
2957 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2958 if(basescr->ffcs[i].data)
2959 if(basescr->ffcs[i].flags&ffc_changer)
2960 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2961
2962 if(flags&cWALK)
2963 {
2964 if(layers[0])
2965 for(int32_t i=0; i<176; i++)
2966 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2967
2968 for(int32_t k=0; k<2; k++)
2969 {
2970 if(layers[k+1])
2971 for(int32_t i=0; i<176; i++)
2972 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2973 }
2974 for(int32_t i=num_ffcs-1; i>=0; i--)
2975 {
2976 if(auto data = basescr->ffcs[i].data)
2977 {
2978 if(!(basescr->ffcs[i].flags&ffc_changer))
2979 {
2980 newcombo const& cmb = combobuf[data];
2981 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2982 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2983
2984 if(basescr->ffcs[i].flags&ffc_solid)
2985 {
2986 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2987 }
2988
2989 if(cmb.type == cSLOPE)
2990 {
2991 slope_info s(cmb, tx, ty);
2992 s.draw(dest, 0, 0, COLOR_SLOPE);
2993 }
2994 }
2995 }
2996 }
2997 }
2998
2999 if(flags&cFLAGS)
3000 {
3001 if(LayerMaskInt[CurrentLayer]!=0)
3002 {
3003 for(int32_t i=0; i<176; i++)
3004 {
3005 if(CurrentLayer==0)
3006 {
3007 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3008 }
3009 else
3010 {
3011 if(prv_mode)
3012 {
3013 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3014 }
3015 else if(basescr->layermap[CurrentLayer-1] > 0)
3016 {
3017 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3018
3019 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3020 {
3021 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3022 TheMaps[_lscr].data[i],
3023 TheMaps[_lscr].cset[i], flags,
3024 TheMaps[_lscr].sflag[i]);
3025 }
3026 }
3027 }
3028 }
3029 }
3030 }
3031
3032 int32_t dark = basescr->flags&cDARK;
3033
3034 if(dark && !(flags&cNODARK)
3035 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3036 {
3037 for(int32_t j=0; j<80; j++)
3038 {
3039 for(int32_t i=0; i<(80)-j; i++)
3040 {
3041 if(((i^j)&1)==0)
3042 {
3043 putpixel(dest,x+i,y+j,vc(blackout_color));
3044 }
3045 }
3046 }
3047 }
3048
3049 if(ShowMisalignments)
3050 {
3051 check_alignments(dest,x,y,screen);
3052 }
3053 }
3054
3055 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3056 {
3057 if(map<0)
3058 map=cursor.map;
3059
3060 if(scr<0)
3061 scr=cursor.screen;
3062
3063 mapscr* layer=AbsoluteScr(map,scr);
3064 int32_t layermap=0, layerscreen=0;
3065
3066 if(!(layer->valid&mVALID))
3067 {
3068 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3069 rectfill(dest,x,y,x+255,y+15,vc(1));
3070 return;
3071 }
3072
3073 int32_t dark = layer->flags&4;
3074
3075 if(LayerMaskInt[0]==0)
3076 {
3077 rectfill(dest,x,y,x+255,y+15,0);
3078 }
3079
3080 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3081 int order[2] = {2,1};
3082 if (olddraw) zc_swap(order[0],order[1]);
3083 for(int k : order)
3084 {
3085 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3086 {
3087 layermap=layer->layermap[k]-1;
3088
3089 if(layermap>-1 && layermap<map_count)
3090 {
3091 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3092
3093 for(int32_t i=c; i<(c&0xF0)+16; i++)
3094 {
3095 auto data = TheMaps[layerscreen].data[i];
3096 auto cs = TheMaps[layerscreen].cset[i];
3097 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3098 }
3099 }
3100 }
3101 }
3102
3103 if(LayerMaskInt[0]!=0)
3104 {
3105 for(int32_t i=c; i<(c&0xF0)+16; i++)
3106 {
3107 word cmbdat = (i < 176 ? layer->data[i] : 0);
3108 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3109 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3110 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3111 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3112 }
3113 }
3114
3115 for(int32_t k=0; k<2; k++)
3116 {
3117 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3118 {
3119 layermap=layer->layermap[k]-1;
3120
3121 if(layermap>-1 && layermap<map_count)
3122 {
3123 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3124
3125 for(int32_t i=c; i<(c&0xF0)+16; i++)
3126 {
3127 auto data = TheMaps[layerscreen].data[i];
3128 auto cs = TheMaps[layerscreen].cset[i];
3129 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3130 }
3131 }
3132 }
3133 }
3134
3135 int32_t doortype[4];
3136
3137 for(int32_t i=0; i<4; i++)
3138 {
3139 switch(layer->door[i])
3140 {
3141 case dOPEN:
3142 doortype[i]=dt_pass;
3143 break;
3144
3145 case dLOCKED:
3146 doortype[i]=dt_lock;
3147 break;
3148
3149 case d1WAYSHUTTER:
3150 case dSHUTTER:
3151 doortype[i]=dt_shut;
3152 break;
3153
3154 case dBOSS:
3155 doortype[i]=dt_boss;
3156 break;
3157
3158 case dBOMB:
3159 doortype[i]=dt_bomb;
3160 break;
3161 }
3162 }
3163
3164 if(c<16)
3165 {
3166 switch(layer->door[up])
3167 {
3168 case dBOMB:
3169 case dOPEN:
3170 case dLOCKED:
3171 case d1WAYSHUTTER:
3172 case dSHUTTER:
3173 case dBOSS:
3174 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3175 break;
3176 }
3177 }
3178 else if(c>159)
3179 {
3180 switch(layer->door[down])
3181 {
3182 case dBOMB:
3183 case dOPEN:
3184 case dLOCKED:
3185 case d1WAYSHUTTER:
3186 case dSHUTTER:
3187 case dBOSS:
3188 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3189 break;
3190 }
3191 }
3192
3193 for(int32_t k=2; k<4; k++)
3194 {
3195 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3196 {
3197 layermap=layer->layermap[k]-1;
3198
3199 if(layermap>-1 && layermap<map_count)
3200 {
3201 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3202
3203 for(int32_t i=c; i<(c&0xF0)+16; i++)
3204 {
3205 if(layer->layeropacity[k]<255)
3206 {
3207 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3208 }
3209 else
3210 {
3211 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3212 }
3213 }
3214 }
3215 }
3216 }
3217
3218 //Overhead L0
3219 if(LayerMaskInt[0]!=0)
3220 {
3221 for(int32_t i=c; i<(c&0xF0)+16; i++)
3222 {
3223 int32_t ct1=layer->data[i];
3224 int32_t ct3=combobuf[ct1].type;
3225
3226 if(combo_class_buf[ct3].overhead)
3227 {
3228 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3229 }
3230 }
3231 }
3232
3233 //Overhead L1/2
3234 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3235 {
3236 for(int32_t k = 0; k < 2; ++k)
3237 {
3238 if(LayerMaskInt[k+1]!=0)
3239 {
3240 layermap=layer->layermap[k]-1;
3241
3242 if(layermap>-1 && layermap<map_count)
3243 {
3244 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3245 for(int32_t i=c; i<(c&0xF0)+16; i++)
3246 {
3247 auto data = TheMaps[layerscreen].data[i];
3248 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3249 auto cs = TheMaps[layerscreen].cset[i];
3250 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3251 }
3252 }
3253 }
3254 }
3255 }
3256
3257 for(int32_t k=4; k<6; k++)
3258 {
3259 if(LayerMaskInt[k+1]!=0)
3260 {
3261 layermap=layer->layermap[k]-1;
3262
3263 if(layermap>-1 && layermap<map_count)
3264 {
3265 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3266
3267 for(int32_t i=c; i<(c&0xF0)+16; i++)
3268 {
3269 auto data = TheMaps[layerscreen].data[i];
3270 auto cs = TheMaps[layerscreen].cset[i];
3271 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3272 }
3273 }
3274 }
3275 }
3276
3277 if(flags&cWALK)
3278 {
3279 if(LayerMaskInt[0]!=0)
3280 {
3281 for(int32_t i=c; i<(c&0xF0)+16; i++)
3282 {
3283 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3284 }
3285 }
3286
3287 for(int32_t k=0; k<2; k++)
3288 {
3289 if(LayerMaskInt[k+1]!=0)
3290 {
3291 for(int32_t i=c; i<(c&0xF0)+16; i++)
3292 {
3293 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3294 }
3295 }
3296 }
3297 }
3298
3299 if(flags&cFLAGS)
3300 {
3301 if(LayerMaskInt[CurrentLayer]!=0)
3302 {
3303 for(int32_t i=c; i<(c&0xF0)+16; i++)
3304 {
3305 if(CurrentLayer==0)
3306 {
3307 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3308 }
3309 else
3310 {
3311 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3312
3313 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3314 {
3315 if(i < 176)
3316 {
3317 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3318 TheMaps[_lscr].data[i],
3319 TheMaps[_lscr].cset[i], flags|dark,
3320 TheMaps[_lscr].sflag[i]);
3321 }
3322 else
3323 {
3324 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3325 }
3326 }
3327 }
3328 }
3329 }
3330
3331 /*
3332 if (LayerMaskInt[0]!=0) {
3333 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3334 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3335 }
3336 }
3337 */
3338 }
3339
3340 if(ShowMisalignments)
3341 {
3342 if(c<16)
3343 {
3344 check_alignments(dest,x,y,scr);
3345 }
3346 else if(c>159)
3347 {
3348 check_alignments(dest,x,y-160,scr);
3349 }
3350 }
3351 }
3352
3353 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3354 {
3355 if(map<0)
3356 map=cursor.map;
3357
3358 if(scr<0)
3359 scr=cursor.screen;
3360
3361 mapscr* layer=AbsoluteScr(map,scr);
3362 int32_t layermap=0, layerscreen=0;
3363
3364 if(!(layer->valid&mVALID))
3365 {
3366 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3367 rectfill(dest,x,y,x+15,y+175,vc(1));
3368 return;
3369 }
3370
3371 int32_t dark = layer->flags&4;
3372
3373 if(LayerMaskInt[0]==0)
3374 {
3375 rectfill(dest,x,y,x+15,y+175,0);
3376 }
3377
3378 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3379 int order[2] = {2,1};
3380 if (olddraw) zc_swap(order[0],order[1]);
3381 for(int k : order)
3382 {
3383 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3384 {
3385 layermap=layer->layermap[k]-1;
3386
3387 if(layermap>-1 && layermap<map_count)
3388 {
3389 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3390
3391 for(int32_t i=c; i<176; i+=16)
3392 {
3393 auto data = TheMaps[layerscreen].data[i];
3394 auto cs = TheMaps[layerscreen].cset[i];
3395 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3396 }
3397 }
3398 }
3399 }
3400
3401 if(LayerMaskInt[0]!=0)
3402 {
3403 for(int32_t i=c; i<176; i+=16)
3404 {
3405 word cmbdat = layer->data[i];
3406 byte cmbcset = layer->cset[i];
3407 int32_t cmbflag = layer->sflag[i];
3408 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3409 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3410 }
3411 }
3412
3413 for(int32_t k=0; k<2; k++)
3414 {
3415 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3416 {
3417 layermap=layer->layermap[k]-1;
3418
3419 if(layermap>-1 && layermap<map_count)
3420 {
3421 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3422
3423 for(int32_t i=c; i<176; i+=16)
3424 {
3425 auto data = TheMaps[layerscreen].data[i];
3426 auto cs = TheMaps[layerscreen].cset[i];
3427 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3428 }
3429 }
3430 }
3431 }
3432
3433 int32_t doortype[4];
3434
3435 for(int32_t i=0; i<4; i++)
3436 {
3437 switch(layer->door[i])
3438 {
3439 case dOPEN:
3440 doortype[i]=dt_pass;
3441 break;
3442
3443 case dLOCKED:
3444 doortype[i]=dt_lock;
3445 break;
3446
3447 case d1WAYSHUTTER:
3448 case dSHUTTER:
3449 doortype[i]=dt_shut;
3450 break;
3451
3452 case dBOSS:
3453 doortype[i]=dt_boss;
3454 break;
3455
3456 case dBOMB:
3457 doortype[i]=dt_bomb;
3458 break;
3459 }
3460 }
3461
3462 if((c&0x0F)==0)
3463 {
3464 switch(layer->door[left])
3465 {
3466
3467 case dBOMB:
3468 case dOPEN:
3469 case dLOCKED:
3470 case d1WAYSHUTTER:
3471 case dSHUTTER:
3472 case dBOSS:
3473 // put_door(dest,64,left,doortype[left],x+256,y,true);
3474 put_door(dest,64,left,doortype[left],x,y,true,scr);
3475 break;
3476 }
3477 }
3478 else if((c&0x0F)==15)
3479 {
3480 switch(layer->door[right])
3481 {
3482 case dBOMB:
3483 case dOPEN:
3484 case dLOCKED:
3485 case d1WAYSHUTTER:
3486 case dSHUTTER:
3487 case dBOSS:
3488 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3489 break;
3490 }
3491 }
3492
3493 for(int32_t k=2; k<4; k++)
3494 {
3495 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3496 {
3497 layermap=layer->layermap[k]-1;
3498
3499 if(layermap>-1 && layermap<map_count)
3500 {
3501 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3502
3503 for(int32_t i=c; i<176; i+=16)
3504 {
3505 auto data = TheMaps[layerscreen].data[i];
3506 auto cs = TheMaps[layerscreen].cset[i];
3507 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3508 }
3509 }
3510 }
3511 }
3512
3513 //Overhead L0
3514 if(LayerMaskInt[0]!=0)
3515 {
3516 for(int32_t i=c; i<176; i+=16)
3517 {
3518 auto data = TheMaps[layerscreen].data[i];
3519 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3520 auto cs = TheMaps[layerscreen].cset[i];
3521 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3522 }
3523 }
3524 //Overhead L1/2
3525 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3526 {
3527 for(int32_t k = 0; k < 2; ++k)
3528 {
3529 if(LayerMaskInt[k+1]!=0)
3530 {
3531 layermap=layer->layermap[k]-1;
3532
3533 if(layermap>-1 && layermap<map_count)
3534 {
3535 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3536 for(int32_t i=c; i<176; i+=16)
3537 {
3538 auto data = TheMaps[layerscreen].data[i];
3539 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3540 auto cs = TheMaps[layerscreen].cset[i];
3541 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3542 }
3543 }
3544 }
3545 }
3546 }
3547
3548
3549 for(int32_t k=4; k<6; k++)
3550 {
3551 if(LayerMaskInt[k+1]!=0)
3552 {
3553 layermap=layer->layermap[k]-1;
3554
3555 if(layermap>-1 && layermap<map_count)
3556 {
3557 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3558
3559 for(int32_t i=c; i<176; i+=16)
3560 {
3561 auto data = TheMaps[layerscreen].data[i];
3562 auto cs = TheMaps[layerscreen].cset[i];
3563 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3564 }
3565 }
3566 }
3567 }
3568
3569 if(flags&cWALK)
3570 {
3571 if(LayerMaskInt[0]!=0)
3572 {
3573 for(int32_t i=c&0xF; i<176; i+=16)
3574 {
3575 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3576 }
3577 }
3578
3579 for(int32_t k=0; k<2; k++)
3580 {
3581 if(LayerMaskInt[k+1]!=0)
3582 {
3583 for(int32_t i=c&0xF; i<176; i+=16)
3584 {
3585 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3586 }
3587 }
3588 }
3589 }
3590
3591 if(flags&cFLAGS)
3592 {
3593 if(LayerMaskInt[CurrentLayer]!=0)
3594 {
3595 for(int32_t i=c; i<176; i+=16)
3596 {
3597 if(CurrentLayer==0)
3598 {
3599 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3600 }
3601 else
3602 {
3603 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3604
3605 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3606 {
3607 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3608 TheMaps[_lscr].data[i],
3609 TheMaps[_lscr].cset[i], flags|dark,
3610 TheMaps[_lscr].sflag[i]);
3611 }
3612 }
3613 }
3614 }
3615 }
3616
3617 if(ShowMisalignments)
3618 {
3619 if((c&0x0F)==0)
3620 {
3621 check_alignments(dest,x,y,scr);
3622 }
3623 else if((c&0x0F)==15)
3624 {
3625 check_alignments(dest,x-240,y,scr);
3626 }
3627 }
3628 }
3629
3630 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3631 {
3632 if(map<0)
3633 map=cursor.map;
3634
3635 if(scr<0)
3636 scr=cursor.screen;
3637
3638 mapscr* layer=AbsoluteScr(map,scr);
3639 int32_t layermap=0, layerscreen=0;
3640
3641 if(!(layer->valid&mVALID))
3642 {
3643 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3644 rectfill(dest,x,y,x+15,y+15,vc(1));
3645 return;
3646 }
3647
3648 int32_t dark = layer->flags&4;
3649
3650 if(LayerMaskInt[0]!=0)
3651 {
3652 rectfill(dest,x,y,x+15,y+15,0);
3653 }
3654
3655 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3656 int order[2] = {2,1};
3657 if (olddraw) zc_swap(order[0],order[1]);
3658 for(int k : order)
3659 {
3660 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3661 {
3662 layermap=layer->layermap[k]-1;
3663
3664 if(layermap>-1 && layermap<map_count)
3665 {
3666 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3667
3668 auto data = TheMaps[layerscreen].data[c];
3669 auto cs = TheMaps[layerscreen].cset[c];
3670 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3671 }
3672 }
3673 }
3674
3675 if(LayerMaskInt[0]!=0)
3676 {
3677 word cmbdat = layer->data[c];
3678 byte cmbcset = layer->cset[c];
3679 int32_t cmbflag = layer->sflag[c];
3680 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3681 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3682 }
3683
3684
3685 for(int32_t k=0; k<2; k++)
3686 {
3687 if(LayerMaskInt[k+1]!=0)
3688 {
3689 layermap=layer->layermap[k]-1;
3690
3691 if(layermap>-1 && layermap<map_count)
3692 {
3693 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3694
3695 auto data = TheMaps[layerscreen].data[c];
3696 auto cs = TheMaps[layerscreen].cset[c];
3697 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3698 }
3699 }
3700 }
3701
3702 for(int32_t k=2; k<4; k++)
3703 {
3704 if(LayerMaskInt[k+1]!=0)
3705 {
3706 layermap=layer->layermap[k]-1;
3707
3708 if(layermap>-1 && layermap<map_count)
3709 {
3710 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3711 auto data = TheMaps[layerscreen].data[c];
3712 auto cs = TheMaps[layerscreen].cset[c];
3713 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3714 }
3715 }
3716 }
3717
3718 //Overhead L0
3719 if(LayerMaskInt[0]!=0)
3720 {
3721 auto data = TheMaps[layerscreen].data[c];
3722 if(combo_class_buf[combobuf[data].type].overhead)
3723 {
3724 auto cs = TheMaps[layerscreen].cset[c];
3725 drawcombo(dest,x,y,data,cs,0,0);
3726 }
3727 }
3728 //Overhead L1/2
3729 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3730 {
3731 for(int32_t k = 0; k < 2; ++k)
3732 {
3733 if(LayerMaskInt[k+1]!=0)
3734 {
3735 layermap=layer->layermap[k]-1;
3736
3737 if(layermap>-1 && layermap<map_count)
3738 {
3739 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3740 auto data = TheMaps[layerscreen].data[c];
3741 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3742 auto cs = TheMaps[layerscreen].cset[c];
3743 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3744 }
3745 }
3746 }
3747 }
3748
3749
3750 for(int32_t k=4; k<6; k++)
3751 {
3752 if(LayerMaskInt[k+1]!=0)
3753 {
3754 layermap=layer->layermap[k]-1;
3755
3756 if(layermap>-1 && layermap<map_count)
3757 {
3758 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3759 auto data = TheMaps[layerscreen].data[c];
3760 auto cs = TheMaps[layerscreen].cset[c];
3761 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3762 }
3763 }
3764 }
3765
3766 if(flags&cWALK)
3767 {
3768 if(LayerMaskInt[0]!=0)
3769 {
3770 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3771 }
3772
3773 for(int32_t k=0; k<2; k++)
3774 {
3775 if(LayerMaskInt[k+1]!=0)
3776 {
3777 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3778 }
3779 }
3780 }
3781
3782 if(flags&cFLAGS)
3783 {
3784 if(LayerMaskInt[CurrentLayer]!=0)
3785 {
3786 int32_t i = c;
3787 //for(int32_t i=c; i==c; i++)
3788 {
3789 if(CurrentLayer==0)
3790 {
3791 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3792 }
3793 else
3794 {
3795 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3796
3797 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3798 {
3799 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3800 TheMaps[_lscr].data[i],
3801 TheMaps[_lscr].cset[i], flags|dark,
3802 TheMaps[_lscr].sflag[i]);
3803 }
3804 }
3805 }
3806 }
3807 }
3808
3809 if(ShowMisalignments)
3810 {
3811 switch(c)
3812 {
3813 case 0:
3814 check_alignments(dest,x,y,scr);
3815 break;
3816
3817 case 15:
3818 check_alignments(dest,x-240,y,scr);
3819 break;
3820
3821 case 160:
3822 check_alignments(dest,x,y-160,scr);
3823 break;
3824
3825 case 175:
3826 check_alignments(dest,x-240,y-160,scr);
3827 break;
3828 }
3829 }
3830 }
3831
3832 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3833 {
3834 if (InvalidBG == 2)
3835 {
3836 draw_checkerboard(dest, x, y, 16);
3837 }
3838 else if(InvalidBG == 1)
3839 {
3840 for(int32_t dy=0; dy<16; dy++)
3841 {
3842 for(int32_t dx=0; dx<16; dx++)
3843 {
3844 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3845 }
3846 }
3847 }
3848 else
3849 {
3850 rectfill(dest, x, y, x+15, y+15, vc(0));
3851 rect(dest, x, y, x+15, y+15, vc(15));
3852 line(dest, x, y, x+15, y+15, vc(15));
3853 line(dest, x, y+15, x+15, y, vc(15));
3854 }
3855 }
3856
3857 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3858 {
3859 if (InvalidBG == 2)
3860 {
3861 for(int32_t q = 0; q < 11; ++q)
3862 draw_checkerboard(dest, x, y + q * 16, 16);
3863 }
3864 else if(InvalidBG == 1)
3865 {
3866 for(int32_t dy=0; dy<176; dy++)
3867 {
3868 for(int32_t dx=0; dx<16; dx++)
3869 {
3870 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3871 }
3872 }
3873 }
3874 else
3875 {
3876 rectfill(dest, x, y, x+15, y+175, vc(0));
3877 rect(dest, x, y, x+15, y+175, vc(15));
3878 line(dest, x, y, x+15, y+175, vc(15));
3879 line(dest, x, y+175, x+15, y, vc(15));
3880 }
3881 }
3882
3883 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3884 {
3885 if (InvalidBG == 2)
3886 {
3887 for (int32_t q = 0; q < 16; ++q)
3888 draw_checkerboard(dest, x + q * 16, y, 16);
3889 }
3890 else if(InvalidBG == 1)
3891 {
3892 for(int32_t dy=0; dy<16; dy++)
3893 {
3894 for(int32_t dx=0; dx<256; dx++)
3895 {
3896 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3897 }
3898 }
3899 }
3900 else
3901 {
3902 rectfill(dest, x, y, x+255, y+15, vc(0));
3903 rect(dest, x, y, x+255, y+15, vc(15));
3904 line(dest, x, y, x+255, y+15, vc(15));
3905 line(dest, x, y+15, x+255, y, vc(15));
3906 }
3907 }
3908
3909 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3910 {
3911 for(int32_t i=0; i<176; i++)
3912 {
3913 word cmbdat = screens[TEMPLATE].data[i];
3914 byte cmbcset = screens[TEMPLATE].cset[i];
3915 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3916 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3917 }
3918 }
3919
3920 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3921 {
3922 for(int32_t i=0; i<176; i++)
3923 {
3924 word cmbdat = screens[TEMPLATE2].data[i];
3925 byte cmbcset = screens[TEMPLATE2].cset[i];
3926 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3927 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3928 }
3929 }
3930
3931 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3932 {
3933 word cmbdat = screens[TEMPLATE].data[pos];
3934 byte cmbcset = screens[TEMPLATE].cset[pos];
3935 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3936 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3937 }
3938
3939 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3940 {
3941 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3942 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3943 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3944 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3945 }
3946
3947 void zmap::scroll(int32_t dir, bool warp)
3948 {
3949 if(cursor.map<map_count)
3950 {
3951 switch(dir)
3952 {
3953 case up:
3954 if(warp && Map.CurrScr()->flags2&wfUP)
3955 {
3956 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3957 }
3958 else if(cursor.screen>15)
3959 {
3960 setCurrScr(cursor.screen - 16);
3961 }
3962
3963 break;
3964
3965 case down:
3966 if(warp && Map.CurrScr()->flags2&wfDOWN)
3967 {
3968 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3969 }
3970 else if(cursor.screen<MAPSCRS-16)
3971 {
3972 setCurrScr(cursor.screen + 16);
3973 }
3974
3975 break;
3976
3977 case left:
3978 if(warp && Map.CurrScr()->flags2&wfLEFT)
3979 {
3980 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3981 }
3982 else if(cursor.screen&15)
3983 {
3984 setCurrScr(cursor.screen - 1);
3985 }
3986
3987 break;
3988
3989 case right:
3990 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3991 {
3992 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3993 }
3994 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3995 {
3996 setCurrScr(cursor.screen + 1);
3997 }
3998
3999 break;
4000 }
4001 }
4002 }
4003
4004 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
4005 {
4006 switch(side)
4007 {
4008 case up:
4009 switch(door)
4010 {
4011 case dWALL:
4012 case dBOMB:
4013 case dWALK:
4014 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4015 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4016 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4017 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4018 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4019 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4020 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4021 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4022 break;
4023
4024 default:
4025 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4026 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4027 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4028 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4029 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4030 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4031 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4032 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4033 break;
4034 }
4035
4036 break;
4037
4038 case down:
4039 switch(door)
4040 {
4041 case dWALL:
4042 case dBOMB:
4043 case dWALK:
4044 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4045 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4046 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4047 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4048 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4049 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4050 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4051 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4052 break;
4053
4054 default:
4055 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4056 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4057 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4058 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4059 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4060 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4061 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4062 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4063 break;
4064 }
4065
4066 break;
4067
4068 case left:
4069 switch(door)
4070 {
4071 case dWALL:
4072 case dBOMB:
4073 case dWALK:
4074 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4075 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4076 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4077 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4078 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4079 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4080 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4081 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4082 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4083 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4084 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4085 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4086 break;
4087
4088 default:
4089 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4090 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4091 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4092 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4093 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4094 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4095 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4096 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4097 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4098 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4099 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4100 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4101 break;
4102 }
4103
4104 break;
4105
4106 case right:
4107 switch(door)
4108 {
4109 case dWALL:
4110 case dBOMB:
4111 case dWALK:
4112 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4113 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4114 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4115 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4116 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4117 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4118 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4119 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4120 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4121 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4122 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4123 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4124 break;
4125
4126 default:
4127 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4128 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4129 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4130 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4131 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4132 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4133 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4134 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4135 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4136 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4137 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4138 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4139 break;
4140 }
4141
4142 break;
4143 }
4144 }
4145 void zmap::DoPutDoorCommand(int side, int door, bool force)
4146 {
4147 if(!force && screens[cursor.screen].door[side] == door)
4148 return;
4149 bool already_list = InListCommand();
4150 if(!already_list)
4151 StartListCommand();
4152 DoSetDoorCommand(cursor.screen,side,door);
4153 if(door != dNONE)
4154 {
4155 word data[176] = {0};
4156 byte cset[176] = {0};
4157 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4158 for(int q = 0; q < 176; ++q)
4159 if(data[q])
4160 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4161 }
4162 if(!already_list)
4163 FinishListCommand();
4164 }
4165 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4166 {
4167 if(screens[screen].door[side] == door)
4168 return;
4169
4170 screens[screen].door[side] = door;
4171 if(door != dNONE)
4172 {
4173 word data[176] = {0};
4174 byte cset[176] = {0};
4175 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4176 for(int q = 0; q < 176; ++q)
4177 if(data[q])
4178 {
4179 screens[screen].data[q] = data[q];
4180 screens[screen].cset[q] = cset[q];
4181 }
4182 }
4183 }
4184
4185 void list_command::execute()
4186 {
4187 for (auto command : commands)
4188 {
4189 command->execute();
4190 }
4191 }
4192
4193 void list_command::undo()
4194 {
4195 for (int i = commands.size() - 1; i >= 0; i--)
4196 {
4197 commands[i]->undo();
4198 }
4199 }
4200
4201 int list_command::size()
4202 {
4203 int s = 0;
4204 for (auto command : commands)
4205 {
4206 s += command->size();
4207 }
4208 return s;
4209 }
4210
4211 void set_combo_command::execute()
4212 {
4213 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4214 if (!scr_ptr) return;
4215
4216 if (combo != -1) scr_ptr->data[pos] = combo;
4217 scr_ptr->cset[pos] = cset;
4218 }
4219
4220 void set_combo_command::undo()
4221 {
4222 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4223 if(!mapscr_ptr) return;
4224 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4225 mapscr_ptr->cset[pos] = prev_cset;
4226 }
4227
4228 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4229 {
4230 std::array<int, 8> initd_arr;
4231 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4232
4233 return {
4234 .x = ffc.x,
4235 .y = ffc.y,
4236 .vx = ffc.vx,
4237 .vy = ffc.vy,
4238 .ax = ffc.ax,
4239 .ay = ffc.ay,
4240 .data = ffc.data,
4241 .cset = ffc.cset,
4242 .delay = ffc.delay,
4243 .link = ffc.link,
4244 .script = ffc.script,
4245 .tw = ffc.txsz,
4246 .th = ffc.tysz,
4247 .ew = ffc.hit_width,
4248 .eh = ffc.hit_height,
4249 .flags = ffc.flags,
4250 .initd = initd_arr,
4251 .layer = ffc.layer
4252 };
4253 }
4254
4255 void set_ffc_command::execute()
4256 {
4257 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4258 if(!mapscr_ptr) return;
4259
4260 mapscr_ptr->valid |= mVALID;
4261 mapscr_ptr->ffcs[i].x = data.x;
4262 mapscr_ptr->ffcs[i].y = data.y;
4263 mapscr_ptr->ffcs[i].vx = data.vx;
4264 mapscr_ptr->ffcs[i].vy = data.vy;
4265 mapscr_ptr->ffcs[i].ax = data.ax;
4266 mapscr_ptr->ffcs[i].ay = data.ay;
4267 mapscr_ptr->ffcs[i].data = data.data;
4268 mapscr_ptr->ffcs[i].cset = data.cset;
4269 mapscr_ptr->ffcs[i].delay = data.delay;
4270 mapscr_ptr->ffcs[i].link = data.link;
4271 mapscr_ptr->ffcs[i].script = data.script;
4272 mapscr_ptr->ffcs[i].flags = data.flags;
4273 mapscr_ptr->ffEffectWidth(i, data.ew);
4274 mapscr_ptr->ffEffectHeight(i, data.eh);
4275 mapscr_ptr->ffTileWidth(i, data.tw);
4276 mapscr_ptr->ffTileHeight(i, data.th);
4277 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4278 mapscr_ptr->ffcs[i].layer = data.layer;
4279 mapscr_ptr->ffcCountMarkDirty();
4280 mapscr_ptr->ffcs[i].updateSolid();
4281 }
4282
4283 void set_ffc_command::undo()
4284 {
4285 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4286 if(!mapscr_ptr) return;
4287
4288 mapscr_ptr->ffcs[i].x = prev_data.x;
4289 mapscr_ptr->ffcs[i].y = prev_data.y;
4290 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4291 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4292 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4293 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4294 mapscr_ptr->ffcs[i].data = prev_data.data;
4295 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4296 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4297 mapscr_ptr->ffcs[i].link = prev_data.link;
4298 mapscr_ptr->ffcs[i].script = prev_data.script;
4299 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4300 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4301 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4302 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4303 mapscr_ptr->ffTileHeight(i, prev_data.th);
4304 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4305 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4306 mapscr_ptr->ffcCountMarkDirty();
4307 mapscr_ptr->ffcs[i].updateSolid();
4308 }
4309
4310 void set_flag_command::execute()
4311 {
4312 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4313 if(!mapscr_ptr) return;
4314
4315 mapscr_ptr->valid |= mVALID;
4316 mapscr_ptr->sflag[pos] = flag;
4317 }
4318
4319 void set_flag_command::undo()
4320 {
4321 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4322 if(!mapscr_ptr) return;
4323 mapscr_ptr->sflag[pos] = prev_flag;
4324 }
4325
4326 void set_door_command::execute()
4327 {
4328 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4329 if(!mapscr_ptr) return;
4330
4331 mapscr_ptr->valid |= mVALID;
4332 mapscr_ptr->door[side] = door;
4333 }
4334
4335 void set_door_command::undo()
4336 {
4337 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4338 }
4339
4340 void set_dcs_command::execute()
4341 {
4342 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4343 if(!mapscr_ptr) return;
4344
4345 mapscr_ptr->valid |= mVALID;
4346 mapscr_ptr->door_combo_set = dcs;
4347 }
4348
4349 void set_dcs_command::undo()
4350 {
4351 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4352 }
4353
4354 void paste_screen_command::execute()
4355 {
4356 perform(screen.get());
4357 }
4358
4359 void paste_screen_command::undo()
4360 {
4361 if (prev_screens.size() > 1)
4362 {
4363 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4364 ASSERT(prev_screens.size() == 128);
4365 for (int i = 0; i < 128; i++)
4366 {
4367 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4368 // TODO: why not just this?
4369 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4370 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4371 }
4372 return;
4373 }
4374
4375 perform(prev_screens[0].get());
4376 }
4377
4378 int paste_screen_command::size()
4379 {
4380 return prev_screens.size() + 1;
4381 }
4382
4383 void paste_screen_command::perform(mapscr* to)
4384 {
4385 if (to)
4386 {
4387 switch (type) {
4388 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4389 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4390 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4391 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4392 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4393 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4394 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4395 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4396 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4397 case ScreenPartial: Map.Paste(*to, screen_index); break;
4398 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4399 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4400 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4401 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4402 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4403 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4404 }
4405 }
4406 else
4407 {
4408 Map.clearscr(screen_index);
4409 }
4410 refresh(rALL);
4411 }
4412
4413 void set_screen_command::execute()
4414 {
4415 if (screen)
4416 {
4417 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4418 }
4419 else
4420 {
4421 Map.clearscr(screen_index);
4422 }
4423 refresh(rALL);
4424 }
4425
4426 void set_screen_command::undo()
4427 {
4428 if (prev_screen)
4429 {
4430 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4431 }
4432 else
4433 {
4434 Map.clearscr(screen_index);
4435 }
4436 refresh(rALL);
4437 }
4438
4439 int set_screen_command::size()
4440 {
4441 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4442 }
4443
4444 static std::shared_ptr<list_command> current_list_command;
4445 void zmap::StartListCommand()
4446 {
4447 ASSERT(!current_list_command);
4448 current_list_command.reset(new list_command);
4449 }
4450
4451 void zmap::FinishListCommand()
4452 {
4453 if (current_list_command->commands.size() == 1)
4454 {
4455 undo_stack.push_back(current_list_command->commands[0]);
4456 }
4457 else if (current_list_command->commands.size() > 1)
4458 {
4459 undo_stack.push_back(current_list_command);
4460 }
4461 CapCommandHistory();
4462 current_list_command = nullptr;
4463 }
4464
4465 void zmap::RevokeListCommand()
4466 {
4467 current_list_command->undo();
4468 current_list_command = nullptr;
4469 }
4470
4471 bool zmap::InListCommand() const
4472 {
4473 return current_list_command ? true : false;
4474 }
4475
4476 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4477 {
4478 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4479 if (!skip_execute) command->execute();
4480 if (current_list_command)
4481 {
4482 current_list_command->commands.push_back(command);
4483 if (current_list_command->commands.size() == 1)
4484 {
4485 current_list_command->cursor = command->cursor;
4486 }
4487 }
4488 else
4489 {
4490 undo_stack.push_back(command);
4491 CapCommandHistory();
4492 }
4493 saved = false;
4494 }
4495
4496 void zmap::UndoCommand()
4497 {
4498 if (undo_stack.size() <= 0) return;
4499
4500 // If not currently looking at the associated screen, first change the view
4501 // and wait for the next call to actually undo this command.
4502 auto command = undo_stack.back();
4503 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4504 {
4505 setCursor(command.get()->cursor);
4506 return;
4507 }
4508
4509 command->undo();
4510 redo_stack.push(command);
4511 undo_stack.pop_back();
4512 saved = false;
4513 }
4514
4515 void zmap::RedoCommand()
4516 {
4517 if (redo_stack.size() <= 0) return;
4518
4519 // If not currently selected the associated screen, first change the cursor
4520 // and wait for the next call to actually execute this command.
4521 auto command = redo_stack.top();
4522 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4523 {
4524 setCursor(command.get()->cursor);
4525 return;
4526 }
4527
4528 command->execute();
4529 undo_stack.push_back(command);
4530 redo_stack.pop();
4531 saved = false;
4532 }
4533
4534 11 void zmap::ClearCommandHistory()
4535 {
4536 11 current_list_command = nullptr;
4537 11 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4538 11 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4539 11 }
4540
4541 // Extra amount is from mapscr's vectors.
4542 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4543 // Allow the undo system to use roughly 100 MB of memory.
4544 // This doesn't count the memory used by commands that don't store a mapscr,
4545 // but that should be negligible.
4546 12 static int max_command_size = 100e6 / size_of_mapscr;
4547 void zmap::CapCommandHistory()
4548 {
4549 int size;
4550 do
4551 {
4552 size = 0;
4553 for (auto command : undo_stack)
4554 {
4555 size += command->size();
4556 }
4557 if (size > max_command_size) undo_stack.pop_front();
4558 } while (size > max_command_size);
4559 }
4560
4561 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4562 {
4563 if (!pos.is_valid(cursor))
4564 return;
4565
4566 int map = cursor.map;
4567 int screen = cursor.viewscr + pos.screen_offset();
4568 if (!AbsoluteScr(map, screen))
4569 return;
4570
4571 if (CurrentLayer)
4572 {
4573 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4574 map = scr->layermap[CurrentLayer-1]-1;
4575 screen = scr->layerscreen[CurrentLayer-1];
4576 }
4577 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4578 }
4579
4580 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4581 {
4582 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4583 if (!mapscr_ptr) return;
4584
4585 std::shared_ptr<set_combo_command> command(new set_combo_command);
4586 command->cursor = cursor;
4587 command->map = map;
4588 command->scr = scr;
4589 command->pos = pos;
4590 command->combo = combo;
4591 command->cset = cset;
4592 command->prev_combo = mapscr_ptr->data[pos];
4593 command->prev_cset = mapscr_ptr->cset[pos];
4594 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4595 {
4596 // nothing to do...
4597 return;
4598 }
4599
4600 ExecuteCommand(command);
4601 }
4602
4603 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4604 {
4605 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4606 if(!mapscr_ptr) return;
4607
4608 mapscr_ptr->ensureFFC(i);
4609
4610 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4611
4612 std::array<int, 8> initd_arr;
4613 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4614
4615 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4616
4617 command->cursor = cursor;
4618 command->map = map;
4619 command->scr = scr;
4620 command->i = i;
4621 command->data = data;
4622 command->prev_data = prev_data;
4623 if (data == prev_data)
4624 {
4625 // nothing to do...
4626 return;
4627 }
4628
4629 ExecuteCommand(command);
4630 }
4631
4632 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4633 {
4634 if (!pos.is_valid(cursor))
4635 return;
4636
4637 int map = cursor.map;
4638 int screen = cursor.viewscr + pos.screen_offset();
4639 if (!AbsoluteScr(map, screen))
4640 return;
4641
4642 if (CurrentLayer)
4643 {
4644 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4645 map = scr->layermap[CurrentLayer-1]-1;
4646 screen = scr->layerscreen[CurrentLayer-1];
4647 }
4648 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4649 }
4650
4651 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4652 {
4653 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4654 if(!mapscr_ptr) return;
4655
4656 std::shared_ptr<set_flag_command> command(new set_flag_command);
4657 command->cursor = cursor;
4658 command->map = map;
4659 command->scr = scr;
4660 command->pos = pos;
4661 command->flag = flag;
4662 command->prev_flag = mapscr_ptr->sflag[pos];
4663 if (command->flag == command->prev_flag)
4664 {
4665 // nothing to do...
4666 return;
4667 }
4668
4669 ExecuteCommand(command);
4670 }
4671
4672 void zmap::DoSetDoorCommand(int scr, int side, int door)
4673 {
4674 if(screens[scr].door[side] == door)
4675 return;
4676 std::shared_ptr<set_door_command> command(new set_door_command);
4677 command->cursor = cursor;
4678 command->side = side;
4679 command->door = door;
4680 command->prev_door = screens[scr].door[side];
4681
4682 ExecuteCommand(command);
4683 }
4684 void zmap::DoSetDCSCommand(int dcs)
4685 {
4686 if(screens[cursor.screen].door_combo_set == dcs)
4687 return;
4688 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4689 command->cursor = cursor;
4690 command->dcs = dcs;
4691 command->prev_dcs = screens[cursor.screen].door_combo_set;
4692
4693 ExecuteCommand(command);
4694 }
4695
4696 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4697 {
4698 if (screen == -1)
4699 screen = cursor.screen;
4700
4701 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4702 command->cursor = cursor;
4703 command->type = type;
4704 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4705 command->screen_index = screen;
4706
4707 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4708 {
4709 for (int i=0; i < 128; i++)
4710 {
4711 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4712 }
4713 }
4714 else
4715 {
4716 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4717 }
4718
4719 ExecuteCommand(command);
4720 }
4721
4722 void zmap::DoClearScreenCommand(int screen)
4723 {
4724 std::shared_ptr<set_screen_command> command(new set_screen_command);
4725 command->cursor = cursor;
4726 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4727 command->screen = std::shared_ptr<mapscr>(nullptr);
4728 command->screen_index = screen;
4729
4730 ExecuteCommand(command);
4731 }
4732
4733 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4734 {
4735 std::shared_ptr<set_screen_command> command(new set_screen_command);
4736 command->cursor = cursor;
4737 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4738 Template(floorcombo, floorcset, screen);
4739 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4740
4741 ExecuteCommand(command, true);
4742 }
4743
4744 void zmap::Copy(int scr)
4745 {
4746 if(screens[scr].valid&mVALID)
4747 {
4748 copy_mapscr(&copymapscr, &screens[scr]);
4749 //copymapscr=screens[scr];
4750 can_paste=true;
4751 copymap=cursor.map;
4752 copyscr=scr;
4753 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4754 copyffc = -1;
4755 }
4756 }
4757
4758 void zmap::CopyFFC(int32_t screen, int32_t n)
4759 {
4760 if(screens[screen].valid&mVALID)
4761 {
4762 copy_mapscr(&copymapscr, &screens[screen]);
4763 // Can't paste the screen itself
4764 can_paste = false;
4765 copymap=cursor.map;
4766 copyscr=screen;
4767 copyffc = n;
4768 }
4769 }
4770
4771 void zmap::Paste(const mapscr& copymapscr, int screen)
4772 {
4773 if(can_paste)
4774 {
4775 if(!(screens[screen].valid&mVALID))
4776 {
4777 screens[screen].valid |= mVALID;
4778 screens[screen].color = copymapscr.color;
4779 }
4780
4781 screens[screen].door_combo_set = copymapscr.door_combo_set;
4782
4783 for(int32_t i=0; i<4; i++)
4784 {
4785 screens[screen].door[i]=copymapscr.door[i];
4786 }
4787
4788 for(int32_t i=0; i<176; i++)
4789 {
4790 screens[screen].data[i] = copymapscr.data[i];
4791 screens[screen].cset[i] = copymapscr.cset[i];
4792 screens[screen].sflag[i] = copymapscr.sflag[i];
4793 }
4794
4795 refresh_color();
4796
4797 saved=false;
4798 }
4799 }
4800
4801 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4802 {
4803 if(can_paste)
4804 {
4805 screens[screen].undercombo = copymapscr.undercombo;
4806 screens[screen].undercset = copymapscr.undercset;
4807 saved=false;
4808 }
4809 }
4810
4811 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4812 {
4813 if(can_paste)
4814 {
4815 for(int32_t i=0; i<128; i++)
4816 {
4817 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4818 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4819 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4820 }
4821
4822 saved=false;
4823 }
4824 }
4825
4826 // TODO const mapscr& copymapscr
4827 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4828 {
4829 if(can_paste)
4830 {
4831 screens[screen].ffcs = copymapscr.ffcs;
4832 screens[screen].ffcCountMarkDirty();
4833 saved=false;
4834 }
4835 }
4836
4837 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4838 {
4839 if(can_paste)
4840 {
4841 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4842
4843 for(int32_t i=0; i<4; i++)
4844 {
4845 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4846 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4847 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4848 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4849 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4850 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4851 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4852 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4853 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4854 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4855 }
4856
4857 saved=false;
4858 }
4859 }
4860
4861 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4862 {
4863 if(can_paste)
4864 {
4865 screens[screen].csensitive = copymapscr.csensitive;
4866 screens[screen].oceansfx = copymapscr.oceansfx;
4867 screens[screen].bosssfx = copymapscr.bosssfx;
4868 screens[screen].secretsfx = copymapscr.secretsfx;
4869 screens[screen].holdupsfx = copymapscr.holdupsfx;
4870 screens[screen].flags = copymapscr.flags;
4871 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4872 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4873 screens[screen].flags3 = copymapscr.flags3;
4874 screens[screen].flags4 = copymapscr.flags4;
4875 screens[screen].flags5 = copymapscr.flags5;
4876 screens[screen].flags6 = copymapscr.flags6;
4877 screens[screen].flags7 = copymapscr.flags7;
4878 screens[screen].flags8 = copymapscr.flags8;
4879 screens[screen].flags9 = copymapscr.flags9;
4880 screens[screen].flags10 = copymapscr.flags10;
4881 screens[screen].flags11 = copymapscr.flags11;
4882 screens[screen].item = copymapscr.item;
4883 screens[screen].hasitem = copymapscr.hasitem;
4884 screens[screen].itemx = copymapscr.itemx;
4885 screens[screen].itemy = copymapscr.itemy;
4886 screens[screen].nextmap = copymapscr.nextmap;
4887 screens[screen].nextscr = copymapscr.nextscr;
4888 screens[screen].nocarry = copymapscr.nocarry;
4889 screens[screen].noreset = copymapscr.noreset;
4890 screens[screen].exstate_reset = copymapscr.exstate_reset;
4891 screens[screen].exstate_carry = copymapscr.exstate_carry;
4892 screens[screen].path[0] = copymapscr.path[0];
4893 screens[screen].path[1] = copymapscr.path[1];
4894 screens[screen].path[2] = copymapscr.path[2];
4895 screens[screen].path[3] = copymapscr.path[3];
4896 screens[screen].pattern = copymapscr.pattern;
4897 screens[screen].exitdir = copymapscr.exitdir;
4898 screens[screen].screen_midi = copymapscr.screen_midi;
4899 screens[screen].stairx = copymapscr.stairx;
4900 screens[screen].stairy = copymapscr.stairy;
4901 screens[screen].timedwarptics = copymapscr.timedwarptics;
4902 saved=false;
4903 }
4904 }
4905
4906 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4907 {
4908 if(can_paste)
4909 {
4910 screens[screen].warpreturnc = copymapscr.warpreturnc;
4911 screens[screen].warparrivalx = copymapscr.warparrivalx;
4912 screens[screen].warparrivaly = copymapscr.warparrivaly;
4913
4914 for(int32_t i=0; i<4; i++)
4915 {
4916 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4917 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4918 }
4919
4920 saved=false;
4921 }
4922 }
4923
4924 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4925 {
4926 if(can_paste)
4927 {
4928 for(int32_t i=0; i<4; i++)
4929 screens[screen].door[i] = copymapscr.door[i];
4930
4931 screens[screen].door_combo_set = copymapscr.door_combo_set;
4932 saved=false;
4933 }
4934 }
4935
4936 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4937 {
4938 if(can_paste)
4939 {
4940 for(int32_t i=0; i<6; i++)
4941 {
4942 screens[screen].layermap[i] = copymapscr.layermap[i];
4943 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4944 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4945 }
4946
4947 saved=false;
4948 }
4949 }
4950
4951 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4952 {
4953 if(can_paste)
4954 {
4955 screens[screen].room = copymapscr.room;
4956 screens[screen].catchall = copymapscr.catchall;
4957 saved=false;
4958 }
4959 }
4960
4961 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4962 {
4963 if(can_paste)
4964 {
4965 screens[screen].guy = copymapscr.guy;
4966 screens[screen].guytile = copymapscr.guytile;
4967 screens[screen].guycs = copymapscr.guycs;
4968 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4969 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4970 screens[screen].str = copymapscr.str;
4971 saved=false;
4972 }
4973 }
4974
4975 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4976 {
4977 if(can_paste)
4978 {
4979 screens[screen].color = copymapscr.color;
4980 screens[screen].valid|=mVALID;
4981 refresh_color();
4982
4983 saved=false;
4984 }
4985 }
4986
4987 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4988 {
4989 if(can_paste)
4990 {
4991 copy_mapscr(&screens[screen], &copymapscr);
4992 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4993 screens[screen].valid|=mVALID;
4994
4995 refresh_color();
4996
4997 saved=false;
4998 }
4999 }
5000
5001
5002 void zmap::PasteToAll(const mapscr& copymapscr)
5003 {
5004 if(can_paste)
5005 {
5006 for(int32_t x=0; x<128; x++)
5007 {
5008 if(!(screens[x].valid&mVALID))
5009 {
5010 screens[x].valid |= mVALID;
5011 screens[x].color = copymapscr.color;
5012 }
5013
5014 for(int32_t i=0; i<176; i++)
5015 {
5016 screens[x].data[i] = copymapscr.data[i];
5017 screens[x].cset[i] = copymapscr.cset[i];
5018 screens[x].sflag[i] = copymapscr.sflag[i];
5019 }
5020 }
5021
5022 refresh_color();
5023
5024 saved=false;
5025 }
5026 }
5027
5028 void zmap::PasteAllToAll(const mapscr& copymapscr)
5029 {
5030 if(can_paste)
5031 {
5032 for(int32_t x=0; x<128; x++)
5033 {
5034 copy_mapscr(&screens[x], &copymapscr);
5035 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5036 //screens[x]=copymapscr;
5037 }
5038
5039 refresh_color();
5040
5041 saved=false;
5042 }
5043 }
5044
5045 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5046 {
5047 if(can_paste)
5048 {
5049 for(int32_t i=0; i<10; i++)
5050 screens[screen].enemy[i]=copymapscr.enemy[i];
5051 }
5052 }
5053
5054 void zmap::setCopyFFC(int32_t n)
5055 {
5056 copyffc = n;
5057 }
5058
5059 void zmap::update_combo_cycling()
5060 {
5061 if(!prv_mode||!prv_cmbcycle)
5062 {
5063 return;
5064 }
5065
5066 int32_t x;
5067 int32_t newdata[176];
5068 int32_t newcset[176];
5069 bool restartanim[MAXCOMBOS] = {0};
5070
5071 for(int32_t i=0; i<176; i++)
5072 {
5073 newdata[i]=-1;
5074 newcset[i]=-1;
5075
5076 x=prvscr.data[i];
5077
5078 //time to restart
5079 if((combobuf[x].aclk>=combobuf[x].speed) &&
5080 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5081 combobuf[x].can_cycle())
5082 {
5083 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5084 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5085
5086 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5087 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5088 int32_t c = newdata[i];
5089
5090 if(combobuf[c].animflags & AF_CYCLE)
5091 {
5092 restartanim[c]=true;
5093 }
5094 }
5095 }
5096
5097 for(int32_t i=0; i<176; i++)
5098 {
5099 x=prvscr.data[i];
5100
5101 //time to restart
5102 if((combobuf[x].aclk>=combobuf[x].speed) &&
5103 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5104 combobuf[x].can_cycle())
5105 {
5106 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5107 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5108
5109 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5110 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5111 int32_t c = newdata[i];
5112
5113 if(combobuf[c].animflags & AF_CYCLE)
5114 {
5115 restartanim[c]=true;
5116 }
5117 }
5118 }
5119
5120 for(int32_t i=0; i<176; i++)
5121 {
5122 if(newdata[i]==-1)
5123 continue;
5124
5125 prvscr.data[i]=newdata[i];
5126 prvscr.cset[i]=newcset[i];
5127 }
5128
5129 word maxffc = prvscr.numFFC();
5130 for(word i=0; i<maxffc; i++)
5131 {
5132 ffcdata& ffc = prvscr.ffcs[i];
5133 newcombo const& cmb = combobuf[ffc.data];
5134
5135 //time to restart
5136 if((cmb.aclk>=cmb.speed) &&
5137 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5138 cmb.can_cycle())
5139 {
5140 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5141 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5142
5143 if(!(cmb.animflags & AF_CYCLENOCSET))
5144 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5145
5146 if(combobuf[ffc.data].animflags & AF_CYCLE)
5147 {
5148 restartanim[ffc.data]=true;
5149 }
5150 prvscr.ffcs[i].data = ffc.data;
5151 prvscr.ffcs[i].cset=ffc.cset;
5152 }
5153 }
5154
5155
5156 if(get_qr(qr_CMBCYCLELAYERS))
5157 {
5158 for(int32_t j=0; j<6; j++)
5159 {
5160 if(!prvlayers[j].valid)
5161 continue;
5162
5163 for(int32_t i=0; i<176; i++)
5164 {
5165 newdata[i]=-1;
5166 newcset[i]=-1;
5167
5168 x=(prvlayers[j]).data[i];
5169
5170 //time to restart
5171 if((combobuf[x].aclk>=combobuf[x].speed) &&
5172 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5173 combobuf[x].can_cycle())
5174 {
5175 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5176 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5177
5178 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5179 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5180 int32_t c = newdata[i];
5181
5182 if(combobuf[c].animflags & AF_CYCLE)
5183 {
5184 restartanim[c]=true;
5185 }
5186 }
5187 }
5188
5189 for(int32_t i=0; i<176; i++)
5190 {
5191 x=(prvlayers[j]).data[i];
5192
5193 //time to restart
5194 if((combobuf[x].aclk>=combobuf[x].speed) &&
5195 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5196 combobuf[x].can_cycle())
5197 {
5198 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5199 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5200
5201 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5202 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5203 int32_t c = newdata[i];
5204
5205 if(combobuf[c].animflags & AF_CYCLE)
5206 {
5207 restartanim[c]=true;
5208 }
5209 }
5210 }
5211
5212 for(int32_t i=0; i<176; i++)
5213 {
5214 if(newdata[i]==-1)
5215 continue;
5216
5217 prvlayers[j].data[i]=newdata[i];
5218 prvlayers[j].cset[i]=newcset[i];
5219 }
5220 }
5221 }
5222
5223 for(int32_t i=0; i<MAXCOMBOS; i++)
5224 {
5225 if(restartanim[i])
5226 {
5227 combobuf[i].tile = combobuf[i].o_tile;
5228 combobuf[i].cur_frame=0;
5229 combobuf[i].aclk = 0;
5230 }
5231 }
5232 }
5233
5234 void zmap::update_freeform_combos()
5235 {
5236 if(!prv_mode||!prv_cmbcycle)
5237 {
5238 return;
5239 }
5240
5241 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5242 word maxffc = prvscr.numFFC();
5243 for(int32_t i=0; i<maxffc; i++)
5244 {
5245 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5246 {
5247 for(int32_t j=0; j<maxffc; j++)
5248 {
5249 if(i!=j)
5250 {
5251 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5252 {
5253 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5254 {
5255 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5256 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5257 {
5258 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5259 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5260 if(prvscr.ffcs[j].flags&ffc_changethis)
5261 {
5262 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5263 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5264 }
5265
5266 if(prvscr.ffcs[j].flags&ffc_changenext)
5267 prvscr.ffcs[i].data += 1;
5268
5269 if(prvscr.ffcs[j].flags&ffc_changeprev)
5270 prvscr.ffcs[i].data -= 1;
5271
5272 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5273 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5274 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5275
5276 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5277 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5278 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5279 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5280
5281 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5282 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5283 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5284 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5285 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5286
5287 if(prvscr.ffcs[i].flags&ffc_carryover)
5288 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5289 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5290
5291 prvscr.ffcs[i].flags&=~ffc_changer;
5292 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5293 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5294
5295 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5296 {
5297 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5298 }
5299
5300 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5301 {
5302 int32_t k=0;
5303
5304 if(prvscr.ffcs[j].flags&ffc_swapnext)
5305 k=j<(MAXFFCS-1)?j+1:0;
5306
5307 if(prvscr.ffcs[j].flags&ffc_swapprev)
5308 k=j>0?j-1:(MAXFFCS-1);
5309
5310 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5311 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5312 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5313 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5314 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5315 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5316 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5317 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5318 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5319 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5320 }
5321 }
5322 }
5323 }
5324 }
5325 }
5326
5327 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5328 {
5329 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5330 {
5331 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5332 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5333 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5334 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5335 }
5336 else
5337 {
5338 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5339 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5340 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5341 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5342 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5343 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5344
5345 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5346 {
5347 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5348
5349 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5350
5351 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5352
5353 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5354 }
5355 }
5356 }
5357 else
5358 {
5359 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5360 prvscr.ffcs[i].delay--;
5361 }
5362
5363 if(prvscr.ffcs[i].x<-32)
5364 {
5365 if(prvscr.flags6&fWRAPAROUNDFF)
5366 {
5367 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5368 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5369 }
5370 else
5371 {
5372 prvscr.ffcs[i].data = 0;
5373 prvscr.ffcs[i].flags&=~ffc_carryover;
5374 }
5375 }
5376
5377 if(prvscr.ffcs[i].y<-32)
5378 {
5379 if(prvscr.flags6&fWRAPAROUNDFF)
5380 {
5381 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5382 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5383 }
5384 else
5385 {
5386 prvscr.ffcs[i].data = 0;
5387 prvscr.ffcs[i].flags&=~ffc_carryover;
5388 }
5389 }
5390
5391 if(prvscr.ffcs[i].x>=288)
5392 {
5393 if(prvscr.flags6&fWRAPAROUNDFF)
5394 {
5395 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5396 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5397 }
5398 else
5399 {
5400 prvscr.ffcs[i].data = 0;
5401 prvscr.ffcs[i].flags&=~ffc_carryover;
5402 }
5403 }
5404
5405 if(prvscr.ffcs[i].y>=208)
5406 {
5407 if(prvscr.flags6&fWRAPAROUNDFF)
5408 {
5409 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5410 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5411 }
5412 else
5413 {
5414 prvscr.ffcs[i].data = 0;
5415 prvscr.ffcs[i].flags&=~ffc_carryover;
5416 }
5417 }
5418
5419 }
5420 }
5421 }
5422
5423 void zmap::goto_dmapscr(int dmap, int scr)
5424 {
5425 setCurrMap(DMaps[dmap].map);
5426 setCurrScr(scr+DMaps[dmap].xoff);
5427 }
5428 void zmap::goto_mapscr(int map, int scr)
5429 {
5430 setCurrMap(map);
5431 setCurrScr(scr);
5432 }
5433
5434 void zmap::dowarp(int32_t type, int32_t index)
5435 {
5436 set_warpback();
5437 if(type==0)
5438 {
5439
5440 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5441 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5442
5443 switch(screens[cursor.screen].tilewarptype[index])
5444 {
5445 case wtCAVE:
5446 case wtNOWARP:
5447 break;
5448
5449 default:
5450 goto_dmapscr(dmap, scr);
5451 break;
5452 }
5453 }
5454 else if(type==1)
5455 {
5456 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5457 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5458
5459 switch(screens[cursor.screen].sidewarptype[index])
5460 {
5461 case wtCAVE:
5462 case wtNOWARP:
5463 break;
5464
5465 default:
5466 goto_dmapscr(dmap, scr);
5467 break;
5468 }
5469 }
5470 }
5471
5472 extern int32_t prv_twon;
5473
5474 void zmap::prv_dowarp(int32_t type, int32_t index)
5475 {
5476 if(type==0)
5477 {
5478
5479 int32_t dmap=prvscr.tilewarpdmap[index];
5480 int32_t scr=prvscr.tilewarpscr[index];
5481
5482 switch(prvscr.tilewarptype[index])
5483 {
5484 case wtCAVE:
5485 case wtNOWARP:
5486 break;
5487
5488 default:
5489 //setCurrMap(DMaps[dmap].map);
5490 //setCurrScr(scr+DMaps[dmap].xoff);
5491 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5492 refresh_color();
5493 //prv_cmbcycle=0;
5494 break;
5495 }
5496 }
5497 else if(type==1)
5498 {
5499 int32_t dmap=prvscr.sidewarpdmap[index];
5500 int32_t scr=prvscr.sidewarpscr[index];
5501
5502 switch(prvscr.sidewarptype[index])
5503 {
5504 case wtCAVE:
5505 case wtNOWARP:
5506 break;
5507
5508 default:
5509 //setCurrMap(DMaps[dmap].map);
5510 //setCurrScr(scr+DMaps[dmap].xoff);
5511 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5512 refresh_color();
5513 //prv_cmbcycle=0;
5514 break;
5515 }
5516 }
5517
5518 if(prv_twon)
5519 {
5520 prv_time=get_prvscr()->timedwarptics;
5521 }
5522 }
5523
5524 void zmap::dowarp2(int32_t ring,int32_t index)
5525 {
5526 set_warpback();
5527 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5528 }
5529
5530 void zmap::set_warpback()
5531 {
5532 warpbackmap = cursor.map;
5533 warpbackscreen = cursor.screen;
5534 }
5535 bool zmap::has_warpback()
5536 {
5537 return warpbackmap && warpbackscreen
5538 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5539 }
5540 void zmap::warpback()
5541 {
5542 if(!has_warpback())
5543 return;
5544
5545 int m = cursor.map, s = cursor.screen;
5546 goto_mapscr(*warpbackmap, *warpbackscreen);
5547 warpbackmap = m;
5548 warpbackscreen = s;
5549 }
5550
5551 bool save_msgstrs(const char *path)
5552 {
5553 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5554
5555 if(!f)
5556 {
5557 return false;
5558 }
5559
5560 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5561 {
5562 pack_fclose(f);
5563 return true;
5564 }
5565
5566 pack_fclose(f);
5567 return false;
5568 }
5569
5570 1 bool save_strings_tsv(const char *path)
5571 {
5572 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5573
5574
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5575 {
5576 return false;
5577 }
5578
5579
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5580 {
5581 1 pack_fclose(f);
5582 1 return true;
5583 }
5584
5585 pack_fclose(f);
5586 return false;
5587 1 }
5588
5589 bool save_msgstrs_text(const char *path)
5590 {
5591 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5592
5593 if(!f)
5594 {
5595 return false;
5596 }
5597
5598 if(writestrings_text(f)==0)
5599 {
5600 pack_fclose(f);
5601 return true;
5602 }
5603
5604 pack_fclose(f);
5605 return false;
5606 }
5607
5608 bool load_msgstrs(const char *path, int32_t startstring)
5609 {
5610 //these are here to bypass compiler warnings about unused arguments
5611 startstring=startstring;
5612
5613 dword section_id;
5614 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5615
5616 if(!f)
5617 {
5618 return false;
5619 }
5620
5621 if(!p_mgetl(&section_id,f))
5622 {
5623 return false;
5624 }
5625
5626 if(section_id==ID_STRINGS)
5627 {
5628 if(readstrings(f, &header)==0)
5629 {
5630 pack_fclose(f);
5631 return true;
5632 }
5633 else
5634 {
5635 pack_fclose(f);
5636 return false;
5637 }
5638 }
5639
5640 pack_fclose(f);
5641 return false;
5642 }
5643
5644 bool load_strings_tsv(const char *path)
5645 {
5646 try
5647 {
5648 parse_strings_tsv(util::read_text_file(path));
5649 }
5650 catch (std::exception& ex)
5651 {
5652 InfoDialog("Import .tsv Error", ex.what()).show();
5653 return false;
5654 }
5655 return true;
5656 }
5657
5658 bool save_pals(const char *path)
5659 {
5660 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5661
5662 if(!f)
5663 {
5664 return false;
5665 }
5666
5667 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5668 {
5669 pack_fclose(f);
5670 return true;
5671 }
5672
5673 pack_fclose(f);
5674 return false;
5675 }
5676
5677 bool load_pals(const char *path, int32_t startcset)
5678 {
5679 dword section_id;
5680 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5681
5682 if(!f)
5683 {
5684 return false;
5685 }
5686
5687 if(!p_mgetl(&section_id,f))
5688 {
5689 return false;
5690 }
5691
5692 if(section_id==ID_CSETS)
5693 {
5694 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5695 {
5696 pack_fclose(f);
5697 loadlvlpal(Color);
5698 return true;
5699 }
5700 else
5701 {
5702 pack_fclose(f);
5703 return false;
5704 }
5705 }
5706
5707 return false;
5708 }
5709
5710 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5711 bool save_guys(const char *path)
5712 {
5713 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5714
5715 if(!f)
5716 {
5717 return false;
5718 }
5719
5720 /*
5721 int32_t id = ID_GUYS;
5722 if(!p_mputl(id,f))
5723 {
5724 return false;
5725 }
5726 */
5727
5728 zquestheader h;
5729 h.zelda_version = 0x250;
5730 h.build = 21;
5731
5732 if(writeguys(f, &h)==0)
5733 {
5734 pack_fclose(f);
5735 return true;
5736 }
5737
5738 pack_fclose(f);
5739 return false;
5740 }
5741
5742 bool load_guys(const char *path)
5743 {
5744 dword section_id;
5745 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5746
5747 if(!f)
5748 {
5749 return false;
5750 }
5751
5752 if(!p_mgetl(&section_id,f))
5753 {
5754 pack_fclose(f);
5755 return false;
5756 }
5757
5758 zquestheader h;
5759 h.zelda_version = 0x250;
5760 h.build = 21;
5761
5762 if(section_id==ID_GUYS)
5763 {
5764 if(readguys(f, &h)==0)
5765 {
5766 pack_fclose(f);
5767 return true;
5768 }
5769 }
5770
5771 pack_fclose(f);
5772 return false;
5773 }
5774
5775
5776 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5777 bool save_combo_alias(const char *path)
5778 {
5779 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5780
5781 if(!f)
5782 {
5783 return false;
5784 }
5785
5786 zquestheader h;
5787 h.zelda_version = 0x250;
5788 h.build = 21;
5789
5790 if(writecomboaliases(f, 0, 0)==0)
5791 {
5792 pack_fclose(f);
5793 return true;
5794 }
5795
5796 pack_fclose(f);
5797 return false;
5798 }
5799
5800 bool load_combo_alias(const char *path)
5801 {
5802 dword section_id;
5803 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5804
5805 if(!f)
5806 {
5807 return false;
5808 }
5809
5810 if(!p_mgetl(&section_id,f))
5811 {
5812 pack_fclose(f);
5813 return false;
5814 }
5815
5816 zquestheader h;
5817 h.zelda_version = 0x250;
5818 h.build = 21;
5819
5820 if(section_id==ID_COMBOALIASES)
5821 {
5822 if(readcomboaliases(f, &h, 0, 0)==0)
5823 {
5824 pack_fclose(f);
5825 return true;
5826 }
5827 }
5828
5829 pack_fclose(f);
5830 return false;
5831 }
5832
5833 bool load_zgp(const char *path)
5834 {
5835 dword section_id;
5836 word section_version;
5837 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5838
5839 if(!f)
5840 return false;
5841
5842 if(!p_mgetl(&section_id,f))
5843 {
5844 pack_fclose(f);
5845 return false;
5846 }
5847
5848 if(section_id!=ID_GRAPHICSPACK)
5849 {
5850 pack_fclose(f);
5851 return false;
5852 }
5853
5854 //section version info
5855 if(!p_igetw(&section_version,f))
5856 {
5857 return 2;
5858 }
5859
5860 if(!read_deprecated_section_cversion(f))
5861 {
5862 return 3;
5863 }
5864
5865 //tiles
5866 if(!p_mgetl(&section_id,f))
5867 {
5868 pack_fclose(f);
5869 return false;
5870 }
5871
5872 if(section_id==ID_TILES)
5873 {
5874 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5875 {
5876 pack_fclose(f);
5877 init_tiles(true, &header);
5878 return false;
5879 }
5880 }
5881 else
5882 {
5883 pack_fclose(f);
5884 return false;
5885 }
5886
5887 //combos
5888 if(!p_mgetl(&section_id,f))
5889 {
5890 pack_fclose(f);
5891 return false;
5892 }
5893
5894 if(section_id==ID_COMBOS)
5895 {
5896 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5897 {
5898 pack_fclose(f);
5899 return false;
5900 }
5901 }
5902 else
5903 {
5904 pack_fclose(f);
5905 return false;
5906 }
5907
5908 //palettes
5909 if(!p_mgetl(&section_id,f))
5910 {
5911 pack_fclose(f);
5912 return false;
5913 }
5914
5915 if(section_id==ID_CSETS)
5916 {
5917 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5918 {
5919 pack_fclose(f);
5920 return false;
5921 }
5922 }
5923 else
5924 {
5925 pack_fclose(f);
5926 return false;
5927 }
5928
5929 //items
5930 if(!p_mgetl(&section_id,f))
5931 {
5932 pack_fclose(f);
5933 return false;
5934 }
5935
5936 if(section_id==ID_ITEMS)
5937 {
5938 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5939 {
5940 pack_fclose(f);
5941 return false;
5942 }
5943 }
5944 else
5945 {
5946 pack_fclose(f);
5947 return false;
5948 }
5949
5950 //weapons
5951 if(!p_mgetl(&section_id,f))
5952 {
5953 pack_fclose(f);
5954 return false;
5955 }
5956
5957 if(section_id==ID_WEAPONS)
5958 {
5959 if(readweapons(f, &header)!=0)
5960 {
5961 pack_fclose(f);
5962 return false;
5963 }
5964 }
5965 else
5966 {
5967 pack_fclose(f);
5968 return false;
5969 }
5970
5971 //read the triforce pieces info and make sure it worked
5972 //really do this?
5973
5974 //read the game icons info and make sure it worked
5975 if(!p_mgetl(&section_id,f))
5976 {
5977 pack_fclose(f);
5978 return false;
5979 }
5980
5981 if(section_id==ID_ICONS)
5982 {
5983 if(readgameicons(f, &header, &QMisc)!=0)
5984 {
5985 pack_fclose(f);
5986 return false;
5987 }
5988 }
5989 else
5990 {
5991 pack_fclose(f);
5992 return false;
5993 }
5994
5995 //read the misc colors info and map styles info and make sure it worked
5996 if(!p_mgetl(&section_id,f))
5997 {
5998 pack_fclose(f);
5999 return false;
6000 }
6001
6002 if(section_id==ID_COLORS)
6003 {
6004 if(readmisccolors(f, &header, &QMisc)!=0)
6005 {
6006 pack_fclose(f);
6007 return false;
6008 }
6009 }
6010 else
6011 {
6012 pack_fclose(f);
6013 return false;
6014 }
6015
6016 //read the door combo sets and make sure it worked
6017 if(!p_mgetl(&section_id,f))
6018 {
6019 pack_fclose(f);
6020 return false;
6021 }
6022
6023 if(section_id==ID_DOORS)
6024 {
6025 if(readdoorcombosets(f, &header)!=0)
6026 {
6027 pack_fclose(f);
6028 return false;
6029 }
6030 }
6031 else
6032 {
6033 pack_fclose(f);
6034 return false;
6035 }
6036
6037 //read the template screens and make sure it worked
6038 //really do this?
6039
6040 //yay! it worked! close the file and say everything was ok.
6041 loadlvlpal(Color);
6042 setup_combo_animations();
6043 setup_combo_animations2();
6044 pack_fclose(f);
6045 return true;
6046 }
6047
6048 bool save_zgp(const char *path)
6049 {
6050 reset_combo_animations();
6051 reset_combo_animations2();
6052
6053 //open the file
6054 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6055
6056 if(!f)
6057 return false;
6058
6059 dword section_id=ID_GRAPHICSPACK;
6060 dword section_version=V_GRAPHICSPACK;
6061
6062 //section id
6063 if(!p_mputl(section_id,f))
6064 {
6065 return 1;
6066 }
6067
6068 //section version info
6069 if(!p_iputw(section_version,f))
6070 {
6071 return 2;
6072 }
6073
6074 if(!write_deprecated_section_cversion(section_version,f))
6075 {
6076 return 3;
6077 }
6078
6079 //tiles
6080 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6081 {
6082 pack_fclose(f);
6083 return false;
6084 }
6085
6086 //combos
6087 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6088 {
6089 pack_fclose(f);
6090 return false;
6091 }
6092
6093 //palettes
6094 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6095 {
6096 pack_fclose(f);
6097 return false;
6098 }
6099
6100 //items
6101 if(writeitems(f, &header)!=0)
6102 {
6103 pack_fclose(f);
6104 return false;
6105 }
6106
6107 //weapons
6108 if(writeweapons(f, &header)!=0)
6109 {
6110 pack_fclose(f);
6111 return false;
6112 }
6113
6114 //write the triforce pieces info and make sure it worked
6115 //really do this?
6116
6117 //write the game icons info and make sure it worked
6118 if(writegameicons(f, &header)!=0)
6119 {
6120 pack_fclose(f);
6121 return false;
6122 }
6123
6124 //write the misc colors info and map styles info and make sure it worked
6125 if(writemisccolors(f, &header)!=0)
6126 {
6127 pack_fclose(f);
6128 return false;
6129 }
6130
6131 //write the door combo sets and make sure it worked
6132 if(writedoorcombosets(f, &header)!=0)
6133 {
6134 pack_fclose(f);
6135 return false;
6136 }
6137
6138 //write the template screens and make sure it worked
6139 //really do this?
6140
6141 pack_fclose(f);
6142 return true;
6143 }
6144
6145 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6146 {
6147 //open the file
6148 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6149
6150 if(!f)
6151 return false;
6152
6153 dword section_id=ID_SUBSCREEN;
6154 dword s_version=V_SUBSCREEN;
6155
6156 if(!p_mputl(section_id,f))
6157 {
6158 pack_fclose(f);
6159 return false;
6160 }
6161
6162 if(!p_iputw(s_version,f))
6163 {
6164 pack_fclose(f);
6165 return false;
6166 }
6167
6168 if(!write_deprecated_section_cversion(s_version,f))
6169 {
6170 pack_fclose(f);
6171 return false;
6172 }
6173
6174 if(savefrom.write(f))
6175 {
6176 pack_fclose(f);
6177 return false;
6178 }
6179
6180 pack_fclose(f);
6181 return true;
6182 }
6183
6184 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6185 {
6186 //open the file
6187 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6188
6189 if(!f)
6190 return false;
6191
6192 dword section_id;
6193 dword s_version;
6194
6195 if(!p_mgetl(&section_id,f))
6196 {
6197 pack_fclose(f);
6198 return false;
6199 }
6200
6201 if(section_id!=ID_SUBSCREEN)
6202 {
6203 pack_fclose(f);
6204 return false;
6205 }
6206
6207 if(!p_igetw(&s_version,f))
6208 {
6209 pack_fclose(f);
6210 return false;
6211 }
6212
6213 if(!read_deprecated_section_cversion(f))
6214 {
6215 pack_fclose(f);
6216 return false;
6217 }
6218
6219 if(s_version < 8)
6220 {
6221 subscreen_group g;
6222 memset(&g,0,sizeof(subscreen_group));
6223 if(read_one_old_subscreen(f,&g,s_version)!=0)
6224 {
6225 pack_fclose(f);
6226 return false;
6227 }
6228 if(g.ss_type != loadto.sub_type)
6229 {
6230 pack_fclose(f);
6231 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6232 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6233 return false;
6234 }
6235 loadto.clear();
6236 if(g.objects[0].type != ssoNULL)
6237 loadto.load_old(g);
6238 }
6239 else
6240 {
6241 ZCSubscreen tmp = ZCSubscreen();
6242 if (tmp.read(f, s_version))
6243 {
6244 pack_fclose(f);
6245 return false;
6246 }
6247 if(tmp.sub_type != loadto.sub_type)
6248 {
6249 pack_fclose(f);
6250 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6251 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6252 return false;
6253 }
6254 loadto.clear();
6255 loadto = tmp;
6256 }
6257
6258 pack_fclose(f);
6259 return true;
6260 }
6261
6262 bool setMapCount2(int32_t c)
6263 {
6264 int32_t oldmapcount=map_count;
6265 int32_t cur_map=Map.getCurrMap();
6266
6267 bound(c,1,MAXMAPS);
6268 map_count=c;
6269
6270 try
6271 {
6272 TheMaps.resize(c*MAPSCRS);
6273 Map.force_refr_pointer();
6274 map_infos.resize(c);
6275 }
6276 catch(...)
6277 {
6278 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6279 return false;
6280 }
6281
6282 bound(cur_map,0,c-1);
6283 if(map_count>oldmapcount)
6284 {
6285 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6286 {
6287 // copy the default palette to the new maps
6288 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6289
6290 Map.setCurrMap(mc);
6291 for(int32_t ms=0; ms<MAPSCRS; ms++)
6292 Map.clearscr(ms);
6293 }
6294 Map.setCurrMap(cur_map);
6295 }
6296 else
6297 {
6298 Map.setCurrMap(cur_map);
6299 if(!layers_valid(Map.CurrScr()))
6300 fix_layers(Map.CurrScr(), false);
6301
6302 for(int32_t i=0; i<MAXDMAPS; i++)
6303 {
6304 if(DMaps[i].map>=map_count)
6305 {
6306 DMaps[i].map=map_count-1;
6307 }
6308 }
6309 }
6310
6311 return true;
6312 }
6313
6314 extern BITMAP *bmap;
6315
6316 static bool loading_file_new = false;
6317 int32_t init_quest(std::string tileset_path)
6318 {
6319 if (tileset_path.empty())
6320 tileset_path = DEFAULT_TILESET;
6321
6322 loading_file_new = true;
6323 load_quest(tileset_path.c_str());
6324 loading_file_new = false;
6325
6326 set_window_title("ZC Editor - Untitled Quest");
6327 zinit.last_map = 0;
6328 zinit.last_screen = 0;
6329
6330 if(bmap != NULL)
6331 {
6332 destroy_bitmap(bmap);
6333 bmap=NULL;
6334 }
6335
6336 return 0;
6337 }
6338
6339 void set_questpwd(std::string_view pwd, bool use_keyfile)
6340 {
6341 header.use_keyfile=use_keyfile;
6342
6343 // string_view actually has some quirks that make it less than ideal here.
6344 // It'd probably be best to replace it, but this works for now.
6345 memset(header.password, 0, 256);
6346 strcpy(header.password, pwd.data());
6347 header.dirty_password=true;
6348
6349 cvs_MD5Context ctx;
6350 cvs_MD5Init(&ctx);
6351 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6352 cvs_MD5Final(header.pwd_hash, &ctx);
6353 }
6354
6355
6356 bool is_null_pwd_hash(uint8_t *pwd_hash)
6357 {
6358 cvs_MD5Context ctx;
6359 uint8_t md5sum[16];
6360 char pwd[2]="";
6361
6362 cvs_MD5Init(&ctx);
6363 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6364 cvs_MD5Final(md5sum, &ctx);
6365
6366 return (memcmp(md5sum,pwd_hash,16)==0);
6367 }
6368
6369 static DIALOG pwd_dlg[] =
6370 {
6371 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6372 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6373 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6374 // 2 (filename)
6375 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6376 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6377 // 4 (challenge hash)
6378 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6379 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6380 // 6 (password)
6381 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6382 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6383 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6384 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6385 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6386 };
6387
6388 int32_t reverse_string(char* str)
6389 {
6390
6391 if(NULL==str)
6392 {
6393 return -1; //no string
6394 }
6395
6396 int32_t l=(int32_t)strlen(str)-1; //get the string length
6397
6398 if(1==l)
6399 {
6400 return 1;
6401 }
6402
6403 char c;
6404
6405 for(int32_t x=0; x < l; x++,l--)
6406 {
6407 c = str[x];
6408 str[x] = str[l];
6409 str[l] = c;
6410 }
6411
6412 return 0;
6413 }
6414
6415 #ifdef __GNUC__
6416 #pragma GCC diagnostic push
6417 #pragma GCC diagnostic ignored "-Wunreachable-code"
6418 #endif
6419
6420 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6421 {
6422
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6423 11 return 1;
6424
6425 #ifdef __EMSCRIPTEN__
6426 return 1;
6427 #endif
6428
6429 //Protection against compiling a release version with password protection off.
6430 static bool passguard = false;
6431
6432 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6433 #define MUST_HAVE_PASSWORD
6434 passguard = true;
6435 #endif
6436
6437 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6438 #if (defined _MSC_VER || defined _NPASS)
6439 return 1;
6440 #endif
6441 #endif
6442 if(devpwd()) return 1;
6443
6444 char hash_string[33];
6445
6446 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6447 {
6448 return 1;
6449 }
6450
6451 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6452 return true;
6453
6454 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6455 pwd_dlg[2].dp=get_filename(filename);
6456 cvs_MD5Context ctx;
6457 uint8_t md5sum[16]={0};
6458 char response[33]="";
6459 char prompt[256]="";
6460
6461 memcpy(md5sum, hdr->pwd_hash, 16);
6462
6463 for(int32_t i=0; i<300; ++i)
6464 {
6465 for(int32_t j=0; j<16; ++j)
6466 {
6467 sprintf(response+j*2, "%02x", md5sum[j]);
6468 }
6469
6470 if(i&1)
6471 {
6472 reverse_string(response);
6473 }
6474
6475 if(i==149)
6476 {
6477 strcpy(hash_string, response);
6478 }
6479
6480 cvs_MD5Init(&ctx);
6481 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6482 cvs_MD5Final(md5sum, &ctx);
6483 }
6484
6485 pwd_dlg[4].dp=hash_string;
6486
6487 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6488 {
6489 sprintf(prompt,"%s",response);
6490 }
6491
6492 pwd_dlg[6].dp=prompt;
6493
6494 large_dialog(pwd_dlg);
6495
6496 int32_t cancel = do_zqdialog(pwd_dlg,6);
6497
6498 if(cancel == 8)
6499 return 2;
6500
6501 bool ret=check_questpwd(hdr, prompt);
6502
6503 if(!ret)
6504 {
6505 ret=(strcmp(response,prompt)==0);
6506 }
6507 return ret ? 1 : 0;
6508 11 }
6509
6510 void set_rules(byte* newrules);
6511 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6512 {
6513 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6514
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6515 {
6516
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6517
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6518 "\nWould you like to apply them?"
6519 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6520 11 [&](bool ret,bool dsa)
6521 {
6522 if(ret)
6523 {
6524 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6525 }
6526 if(dsa)
6527 {
6528 zc_set_config("zquest",cfg,1);
6529 }
6530 },
6531
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6532 0,false, //timeout - none
6533 true //"Don't show this again"
6534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6535 11 }
6536 11 }
6537
6538 #ifdef __GNUC__
6539 #pragma GCC diagnostic pop
6540 #endif
6541
6542 11 int32_t load_quest(const char *filename, bool show_progress)
6543 {
6544 char buf[2048];
6545 byte skip_flags[4];
6546
6547 11 dword tileset_flags = 0;
6548
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6549 {
6550 44 skip_flags[i]=0;
6551 44 }
6552
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6553 7634 set_qr(i,0);
6554 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6555
6556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6557 {
6558 init_quest(DEFAULT_TILESET);
6559 }
6560 else
6561 {
6562 11 int32_t accessret = quest_access(filename, &header);
6563
6564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6565 {
6566 init_quest(DEFAULT_TILESET);
6567
6568 if(accessret == 0)
6569 ret=qe_pwd;
6570 else
6571 ret=qe_cancel;
6572 }
6573 else
6574 {
6575 11 Map.clear();
6576 11 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6577 11 Map.setCurrScr(zinit.last_screen);
6578
6579
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6580
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6581
6582 extern int32_t current_mappage;
6583 11 current_mappage = 0;
6584 11 bool found_default = false;
6585
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6586 {
6587 83 auto &pg = map_page[q];
6588
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6589 {
6590 2 current_mappage = q;
6591 2 break;
6592 }
6593
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6594 72 continue;
6595 else
6596 {
6597 9 current_mappage = q;
6598 9 found_default = true;
6599 }
6600 9 }
6601
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6602
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6603
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6604 11 saved = true;
6605
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6606
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6607
6608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6609 {
6610 destroy_bitmap(bmap);
6611 bmap=NULL;
6612 }
6613
6614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6615 {
6616 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6617 set_window_title(buf);
6618 }
6619 11 }
6620 }
6621
6622 11 Map.ClearCommandHistory();
6623
6624
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6625 {
6626 void load_size_poses();
6627 load_size_poses();
6628 }
6629
6630 11 return ret;
6631 }
6632
6633 int32_t load_tileset(const char *filename, dword tsetflags)
6634 {
6635 byte skip_flags[4];
6636
6637 for(int32_t i=0; i<4; ++i)
6638 skip_flags[i]=0;
6639 for(int32_t i=0; i<qr_MAX; i++)
6640 set_qr(i,0);
6641 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6642
6643 if(ret!=qe_OK)
6644 init_quest(DEFAULT_TILESET);
6645 else
6646 {
6647 if(tsetflags & TILESET_BUGFIX)
6648 applyRuleTemplate(ruletemplateFixCompat);
6649 if(tsetflags & TILESET_SCR_BUGFIX)
6650 applyRuleTemplate(ruletemplateFixZSCompat);
6651
6652 int32_t accessret = quest_access(filename, &header);
6653
6654 if(accessret != 1)
6655 {
6656 init_quest(DEFAULT_TILESET);
6657
6658 if(accessret == 0)
6659 ret=qe_pwd;
6660 else
6661 ret=qe_cancel;
6662 }
6663 else
6664 {
6665 Map.clear();
6666 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6667 Map.setCurrScr(zinit.last_screen);
6668 extern int32_t current_mappage;
6669 current_mappage = 0;
6670 bool found_default = false;
6671 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6672 {
6673 auto &pg = map_page[q];
6674 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6675 {
6676 current_mappage = q;
6677 break;
6678 }
6679 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6680 continue;
6681 else
6682 {
6683 current_mappage = q;
6684 found_default = true;
6685 }
6686 }
6687 refresh(rALL);
6688 refresh_pal();
6689 set_rules(quest_rules);
6690
6691 if(bmap != NULL)
6692 {
6693 destroy_bitmap(bmap);
6694 bmap=NULL;
6695 }
6696
6697 set_window_title("ZC Editor - Untitled Quest");
6698 first_save = saved = false;
6699 memset(filepath,0,255);
6700 memset(temppath,0,255);
6701 }
6702 }
6703
6704 Map.ClearCommandHistory();
6705
6706 return ret;
6707 }
6708
6709 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6710 {
6711
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6712 new_return(1);
6713
6714
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6715 new_return(2);
6716
6717
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6718 new_return(3);
6719
6720
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6721 new_return(4);
6722
6723
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6724 {
6725
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6726 new_return(5);
6727
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6728 new_return(6);
6729 1363650 }
6730
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6731 new_return(7);
6732
6733
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6734 new_return(8);
6735
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6736 new_return(9);
6737
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6738 new_return(10);
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6740 new_return(11);
6741
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6742 new_return(12);
6743
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6744 new_return(13);
6745
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6746 new_return(14);
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6748 new_return(15);
6749
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6750 new_return(16);
6751
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6752 new_return(17);
6753
6754
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6755 new_return(18);
6756
6757
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6758 new_return(19);
6759
6760
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6761 new_return(20);
6762
6763
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6764 new_return(21);
6765
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6766 new_return(22);
6767
6768
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6769 new_return(23);
6770
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6771 new_return(24);
6772
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6773 new_return(25);
6774
6775
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6776 new_return(26);
6777
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6778
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6779 new_return(27);
6780
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6781 new_return(28);
6782 272730 return 0;
6783 }
6784
6785 130 bool write_midi(MIDI *m,PACKFILE *f)
6786 {
6787 int32_t c;
6788
6789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6790
6791
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6792 {
6793
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6794
6795
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6796 {
6797
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6798 return false;
6799 1264 }
6800 4160 }
6801
6802 130 return true;
6803 130 }
6804
6805 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6806 {
6807 9 dword section_id=ID_HEADER;
6808 9 dword section_version=V_HEADER;
6809 9 dword section_size=0;
6810
6811 //file header string
6812
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6813 {
6814 new_return(1);
6815 }
6816
6817 //section id
6818
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6819 {
6820 new_return(2);
6821 }
6822
6823 //section version info
6824
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6825 {
6826 new_return(3);
6827 }
6828
6829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6830 {
6831 new_return(4);
6832 }
6833
6834
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6835 {
6836 18 fake_pack_writing=(writecycle==0);
6837
6838 //section size
6839
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6840 {
6841 new_return(5);
6842 }
6843
6844 18 writesize=0;
6845
6846 //finally... section data
6847
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6848 {
6849 new_return(6);
6850 }
6851
6852
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6853 {
6854 new_return(7);
6855 }
6856
6857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6858 {
6859 new_return(8);
6860 }
6861
6862
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6863 {
6864 new_return(10);
6865 }
6866
6867
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6868 {
6869 new_return(11);
6870 }
6871
6872
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6873 {
6874 new_return(12);
6875 }
6876
6877
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6878 {
6879 new_return(13);
6880 }
6881
6882
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6883 {
6884 new_return(14);
6885 }
6886
6887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6888 {
6889 new_return(15);
6890 }
6891
6892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6893 {
6894 new_return(16);
6895 }
6896
6897
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6898 {
6899 new_return(17);
6900 }
6901
6902
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6903 {
6904 new_return(19);
6905 }
6906
6907
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6908 //this is for map count, it seems. -Z
6909 {
6910 new_return(20);
6911 }
6912
6913 18 auto version = getVersion();
6914
6915
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6916 {
6917 new_return(21);
6918 }
6919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6920 {
6921 new_return(22);
6922 }
6923
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6924 {
6925 new_return(23);
6926 }
6927 // Fourth component is deprecated.
6928
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6929 {
6930 new_return(24);
6931 }
6932
6933 // Numerous prerelease stages is deprecated.
6934
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6935 {
6936 new_return(25);
6937 }
6938
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6939 {
6940 new_return(26);
6941 }
6942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6943 {
6944 new_return(27);
6945 }
6946
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6947 {
6948 new_return(28);
6949 }
6950
6951
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6952 {
6953 new_return(29);
6954 }
6955
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6956 {
6957 new_return(30);
6958 }
6959
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6960 {
6961 new_return(31);
6962 }
6963
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6964 {
6965 new_return(32);
6966 }
6967
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6968 {
6969 new_return(33);
6970 }
6971
6972 // This is no longer set to anything.
6973 const char* tempsig[256];
6974 18 memset(tempsig, 0, 256);
6975
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6976 {
6977 new_return(34);
6978 }
6979
6980 char tempcompilersig[256];
6981 18 memset(tempcompilersig, 0, 256);
6982 18 strcpy(tempcompilersig, COMPILER_NAME);
6983
6984
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6985 {
6986 new_return(35);
6987 }
6988
6989 char tempcompilerversion[256];
6990 18 memset(tempcompilerversion, 0, 256);
6991 #ifdef _MSC_VER
6992 zc_itoa(_MSC_VER,tempcompilerversion,10);
6993 #else
6994 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6995 #endif
6996
6997
6998
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6999 {
7000 new_return(36);
7001 }
7002
7003
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
7004 {
7005 new_return(37);
7006 }
7007
7008 // V_ZC_COMPILERSIG - a deprecated version field.
7009
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
7010 {
7011 new_return(38);
7012 }
7013 #ifdef _MSC_VER
7014 if(!p_iputl((_MSC_VER / 100),f))
7015 {
7016 new_return(39);
7017 }
7018 #else
7019
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7020 {
7021 new_return(39);
7022 }
7023 #endif
7024
7025
7026
7027 #ifdef _MSC_VER
7028 if(!p_iputl((_MSC_VER % 100),f))
7029 {
7030 new_return(41);
7031 }
7032 #else
7033
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7034 {
7035 new_return(41);
7036 }
7037 #endif
7038
7039 #ifdef _MSC_VER
7040 # if _MSC_VER >= 1400
7041 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7042 {
7043 new_return(40);
7044 }
7045 # else
7046 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7047 {
7048 new_return(40);
7049 }
7050 #endif
7051 #else
7052
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7053 {
7054 new_return(40);
7055 }
7056 #endif
7057
7058 #ifdef _MSC_VER
7059 if(!p_iputl((_MSC_BUILD),f))
7060 {
7061 new_return(42);
7062 }
7063 #else
7064
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7065 {
7066 new_return(42);
7067 }
7068 #endif
7069
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7070 {
7071 new_return(43);
7072 }
7073
7074 // Modules were removed (replaced by zinfo).
7075 char tempmodulename[1024];
7076 18 memset(tempmodulename, 0, 1024);
7077
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7078 {
7079 new_return(44);
7080 }
7081
7082 char tempdate[256];
7083 18 memset(tempdate, 0, 256);
7084 18 strcpy(tempdate, __DATE__);
7085
7086
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7087 {
7088 new_return(45);
7089 }
7090 char temptime[256];
7091 18 memset(temptime, 0, 256);
7092 18 strcpy(temptime, __TIME__);
7093
7094
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7095 {
7096 new_return(46);
7097 }
7098
7099
7100 char temptimezone[6];
7101 18 memset(temptimezone, 0, 6);
7102 18 strcpy(temptimezone, __TIMEZONE__);
7103
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7104 {
7105 new_return(47);
7106 }
7107
7108
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7109 {
7110 new_return(48);
7111 }
7112
7113
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7114 {
7115 new_return(49);
7116 }
7117
7118
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7119 {
7120 new_return(50);
7121 }
7122
7123
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7124 {
7125 9 section_size=writesize;
7126 9 }
7127 18 }
7128
7129
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7130 {
7131 char ebuf[80];
7132 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7133 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7134 }
7135
7136 9 new_return(0);
7137 }
7138
7139 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7140 {
7141 //these are here to bypass compiler warnings about unused arguments
7142 9 Header=Header;
7143
7144 9 dword section_id=ID_RULES;
7145 9 dword section_version=V_RULES;
7146 9 dword section_size=0;
7147
7148 //section id
7149
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7150 {
7151 new_return(1);
7152 }
7153
7154 //section version info
7155
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7156 {
7157 new_return(2);
7158 }
7159
7160
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7161 {
7162 new_return(3);
7163 }
7164
7165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7166 {
7167 new_return(6);
7168 }
7169
7170
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7171 {
7172 18 fake_pack_writing=(writecycle==0);
7173
7174 //section size
7175
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7176 {
7177 new_return(4);
7178 }
7179
7180 18 writesize=0;
7181
7182 //finally... section data
7183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7184 {
7185 new_return(5);
7186 }
7187
7188
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7189 {
7190 9 section_size=writesize;
7191 9 }
7192 18 }
7193
7194
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7195 {
7196 char ebuf[80];
7197 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7198 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7199 }
7200
7201 9 new_return(0);
7202 }
7203
7204
7205 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7206 {
7207 //these are here to bypass compiler warnings about unused arguments
7208 9 Header=Header;
7209
7210 9 dword section_id=ID_DOORS;
7211 9 dword section_version=V_DOORS;
7212 9 dword section_size=0;
7213
7214 //section id
7215
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7216 {
7217 new_return(1);
7218 }
7219
7220 //section version info
7221
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7222 {
7223 new_return(2);
7224 }
7225
7226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7227 {
7228 new_return(3);
7229 }
7230
7231
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7232 {
7233 18 fake_pack_writing=(writecycle==0);
7234
7235 //section size
7236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7237 {
7238 new_return(4);
7239 }
7240
7241 18 writesize=0;
7242
7243 //finally... section data
7244
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7245 {
7246 new_return(5);
7247 }
7248
7249
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7250 {
7251 //name
7252 char name[21];
7253 320 memset(name, 21, (char)0);
7254 320 strcpy(name, DoorComboSetNames[i].c_str());
7255
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7256 {
7257 new_return(6);
7258 }
7259
7260 //up door
7261
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7262 {
7263
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7264 {
7265
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7266 {
7267 new_return(7);
7268 }
7269 11520 }
7270 2880 }
7271
7272
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7273 {
7274
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7275 {
7276
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7277 {
7278 new_return(8);
7279 }
7280 11520 }
7281 2880 }
7282
7283 //down door
7284
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7285 {
7286
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7287 {
7288
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7289 {
7290 new_return(9);
7291 }
7292 11520 }
7293 2880 }
7294
7295
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7296 {
7297
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7298 {
7299
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7300 {
7301 new_return(10);
7302 }
7303 11520 }
7304 2880 }
7305
7306
7307 //left door
7308
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7309 {
7310
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7311 {
7312
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7313
7314 {
7315 new_return(11);
7316 }
7317 17280 }
7318 2880 }
7319
7320
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7321 {
7322
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7323 {
7324
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7325 {
7326 new_return(12);
7327 }
7328 17280 }
7329 2880 }
7330
7331 //right door
7332
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7333 {
7334
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7335 {
7336
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7337 {
7338 new_return(13);
7339 }
7340 17280 }
7341 2880 }
7342
7343
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7344 {
7345
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7346 {
7347
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7348 {
7349 new_return(14);
7350 }
7351 17280 }
7352 2880 }
7353
7354
7355 //up bomb rubble
7356
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7357 {
7358
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7359 {
7360 new_return(15);
7361 }
7362 640 }
7363
7364
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7365 {
7366
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7367 {
7368 new_return(16);
7369 }
7370 640 }
7371
7372 //down bomb rubble
7373
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7374 {
7375
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7376 {
7377 new_return(17);
7378 }
7379 640 }
7380
7381
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7382 {
7383
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7384 {
7385 new_return(18);
7386 }
7387 640 }
7388
7389 //left bomb rubble
7390
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7391 {
7392
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7393 {
7394 new_return(19);
7395 }
7396 960 }
7397
7398
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7399 {
7400
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7401 {
7402 new_return(20);
7403 }
7404 960 }
7405
7406 //right bomb rubble
7407
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7408 {
7409
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7410 {
7411 new_return(21);
7412 }
7413 960 }
7414
7415
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7416 {
7417
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7418 {
7419 new_return(22);
7420 }
7421 960 }
7422
7423 //walkthrough stuff
7424
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7425 {
7426
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7427 {
7428 new_return(23);
7429 }
7430 1280 }
7431
7432
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7433 {
7434
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7435 {
7436 new_return(24);
7437 }
7438 1280 }
7439
7440 //flags
7441
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7442 {
7443
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7444 {
7445 new_return(25);
7446 }
7447 640 }
7448 320 }
7449
7450
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7451 {
7452 9 section_size=writesize;
7453 9 }
7454 18 }
7455
7456
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7457 {
7458 char ebuf[80];
7459 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7460 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7461 }
7462
7463 9 new_return(0);
7464 }
7465
7466 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7467 {
7468 //these are here to bypass compiler warnings about unused arguments
7469 9 version=version;
7470 9 build=build;
7471
7472 9 word dmap_count=count_dmaps();
7473 9 dword section_id=ID_DMAPS;
7474 9 dword section_version=V_DMAPS;
7475 9 dword section_size=0;
7476
7477 //section id
7478
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7479 {
7480 new_return(1);
7481 }
7482
7483 //section version info
7484
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7485 {
7486 new_return(2);
7487 }
7488
7489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7490 {
7491 new_return(3);
7492 }
7493
7494
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7495 {
7496 18 fake_pack_writing=(writecycle==0);
7497
7498 //section size
7499
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7500 {
7501 new_return(4);
7502 }
7503
7504 18 writesize=0;
7505
7506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7508
7509 //finally... section data
7510
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7511 {
7512 new_return(5);
7513 }
7514
7515
7516
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7517 {
7518 9216 DMaps[i].validate_subscreens();
7519
7520
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7521 {
7522 new_return(6);
7523 }
7524
7525
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7526 {
7527 new_return(7);
7528 }
7529
7530
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7531 {
7532 new_return(8);
7533 }
7534
7535
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7536 {
7537 new_return(9);
7538 }
7539
7540
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7541 {
7542 new_return(10);
7543 }
7544
7545
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7546 {
7547 new_return(11);
7548 }
7549
7550
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7551 {
7552 new_return(12);
7553 }
7554
7555
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7556 {
7557 new_return(13);
7558 }
7559
7560
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7561 {
7562
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7563 {
7564 new_return(14);
7565 }
7566 73728 }
7567
7568
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7569 {
7570 new_return(15);
7571 }
7572
7573
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7574 {
7575 new_return(16);
7576 }
7577
7578
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7579 {
7580 new_return(17);
7581 }
7582
7583
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[0],f))
7584 {
7585 new_return(18);
7586 }
7587
7588
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[0],f))
7589 {
7590 new_return(19);
7591 }
7592
7593
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[1],f))
7594 {
7595 new_return(20);
7596 }
7597
7598
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[1],f))
7599 {
7600 new_return(21);
7601 }
7602
7603
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[0],f))
7604 {
7605 new_return(22);
7606 }
7607
7608
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[0],f))
7609 {
7610 new_return(23);
7611 }
7612
7613
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[1],f))
7614 {
7615 new_return(24);
7616 }
7617
7618
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[1],f))
7619 {
7620 new_return(25);
7621 }
7622
7623
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7624 {
7625 new_return(26);
7626 }
7627
7628
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7629 {
7630 new_return(25);
7631 }
7632
7633
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7634 {
7635 new_return(26);
7636 }
7637
7638
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7639 {
7640 new_return(27);
7641 }
7642
7643 byte disabled[32];
7644 9216 memset(disabled,0,32);
7645
7646
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7647 {
7648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359296 times.
2359296 if(DMaps[i].disableditems[j])
7649 {
7650 disabled[j/8] |= (1 << (j%8));
7651 }
7652 2359296 }
7653
7654
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7655 {
7656 new_return(28);
7657 }
7658
7659
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7660 {
7661 new_return(29);
7662 }
7663
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7664 {
7665 new_return(30);
7666 }
7667
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7668 {
7669 new_return(31);
7670 }
7671
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7672 {
7673
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7674 {
7675 new_return(32);
7676 }
7677
7678 73728 }
7679
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7680 {
7681
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7682 {
7683
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7684 {
7685 new_return(33);
7686 }
7687 4792320 }
7688 73728 }
7689
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7690 {
7691 new_return(34);
7692 }
7693
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7694 {
7695 new_return(35);
7696 }
7697
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7698 {
7699
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7700 {
7701 new_return(36);
7702 }
7703 73728 }
7704
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7705 {
7706
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7707 {
7708
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7709 {
7710 new_return(37);
7711 }
7712 4792320 }
7713 73728 }
7714
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7715 {
7716 new_return(38);
7717 }
7718
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7719 {
7720
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7721 {
7722 new_return(39);
7723 }
7724 73728 }
7725
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7726 {
7727
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7728 {
7729
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7730 {
7731 new_return(40);
7732 }
7733 4792320 }
7734 73728 }
7735
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7736 {
7737 new_return(41);
7738 }
7739
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7740 {
7741 new_return(42);
7742 }
7743
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7744 {
7745 new_return(43);
7746 }
7747
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7748 {
7749 new_return(44);
7750 }
7751
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7752 {
7753 new_return(45);
7754 }
7755
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7756 new_return(46);
7757
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7758 new_return(47);
7759
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[i].flags & dmfCUSTOM_GRAVITY)
7760 {
7761 if (!p_iputzf(DMaps[i].dmap_gravity, f))
7762 new_return(48);
7763 if (!p_iputzf(DMaps[i].dmap_terminal_v, f))
7764 new_return(49);
7765 }
7766 9216 }
7767
7768
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7769 {
7770 9 section_size=writesize;
7771 9 }
7772 18 }
7773
7774
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7775 {
7776 char ebuf[80];
7777 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7778 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7779 }
7780
7781 9 new_return(0);
7782 }
7783
7784 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7785 {
7786 //these are here to bypass compiler warnings about unused arguments
7787 9 Header=Header;
7788
7789 9 dword section_id=ID_COLORS;
7790 9 dword section_version=V_COLORS;
7791 9 dword section_size = 0;
7792
7793 //section id
7794
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7795 {
7796 new_return(1);
7797 }
7798
7799
7800 //section version info
7801
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7802 {
7803 new_return(2);
7804 }
7805
7806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7807 {
7808 new_return(3);
7809 }
7810
7811
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7812 {
7813 18 fake_pack_writing=(writecycle==0);
7814
7815 //section size
7816
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7817 {
7818 new_return(4);
7819 }
7820
7821 18 writesize=0;
7822
7823
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7824 {
7825 new_return(5);
7826 }
7827
7828
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7829 {
7830 new_return(6);
7831 }
7832
7833
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7834 {
7835 new_return(7);
7836 }
7837
7838
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7839 {
7840 new_return(8);
7841 }
7842
7843
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7844 {
7845 new_return(9);
7846 }
7847
7848
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7849 {
7850 new_return(10);
7851 }
7852
7853
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7854 {
7855 new_return(11);
7856 }
7857
7858
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7859 {
7860 new_return(12);
7861 }
7862
7863
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7864 {
7865 new_return(13);
7866 }
7867
7868
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7869 {
7870 new_return(14);
7871 }
7872
7873
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7874 {
7875 new_return(15);
7876 }
7877
7878
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7879 {
7880 new_return(16);
7881 }
7882
7883
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7884 {
7885 new_return(17);
7886 }
7887
7888
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7889 {
7890 new_return(18);
7891 }
7892
7893
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7894 {
7895 new_return(19);
7896 }
7897
7898
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7899 {
7900 new_return(20);
7901 }
7902
7903
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7904 {
7905 new_return(21);
7906 }
7907
7908
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7909 {
7910 new_return(22);
7911 }
7912
7913
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7914 {
7915 new_return(23);
7916 }
7917
7918
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7919 {
7920 new_return(24);
7921 }
7922
7923
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7924 {
7925 new_return(31);
7926 }
7927
7928
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7929 {
7930 new_return(32);
7931 }
7932
7933
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7934 {
7935 new_return(33);
7936 }
7937
7938
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7939 {
7940 new_return(34);
7941 }
7942
7943
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7944 {
7945 new_return(35);
7946 }
7947
7948
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7949 {
7950 new_return(36);
7951 }
7952
7953
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7954 {
7955 new_return(37);
7956 }
7957
7958
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7959 {
7960 new_return(38);
7961 }
7962
7963
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7964 {
7965 new_return(39);
7966 }
7967
7968
7969
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7970 {
7971 9 section_size=writesize;
7972 9 }
7973 18 }
7974
7975
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7976 {
7977 char ebuf[80];
7978 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7979 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7980 }
7981
7982 9 new_return(0);
7983 }
7984
7985 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7986 {
7987 //these are here to bypass compiler warnings about unused arguments
7988 9 Header=Header;
7989
7990 9 dword section_id=ID_ICONS;
7991 9 dword section_version=V_ICONS;
7992 9 dword section_size = 0;
7993
7994 //section id
7995
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7996 {
7997 new_return(1);
7998 }
7999
8000 //section version info
8001
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8002 {
8003 new_return(2);
8004 }
8005
8006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8007 {
8008 new_return(3);
8009 }
8010
8011
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8012 {
8013 18 fake_pack_writing=(writecycle==0);
8014
8015 //section size
8016
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8017 {
8018 new_return(4);
8019 }
8020
8021 18 writesize=0;
8022
8023
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
8024 {
8025
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
8026 {
8027 new_return(5);
8028 }
8029 72 }
8030
8031
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8032 {
8033 9 section_size=writesize;
8034 9 }
8035 18 }
8036
8037
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8038 {
8039 char ebuf[80];
8040 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8041 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8042 }
8043
8044 9 new_return(0);
8045 }
8046
8047 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8048 {
8049 //these are here to bypass compiler warnings about unused arguments
8050 9 Header=Header;
8051
8052 9 dword section_id=ID_MISC;
8053 9 dword section_version=V_MISC;
8054 9 word shops=count_shops(&QMisc);
8055 9 word infos=count_infos(&QMisc);
8056 9 word warprings=count_warprings(&QMisc);
8057 9 word triforces=8;
8058 9 dword section_size = 0;
8059
8060 //section id
8061
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8062 {
8063 new_return(1);
8064 }
8065
8066
8067 //section version info
8068
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8069 {
8070 new_return(2);
8071 }
8072
8073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8074 {
8075 new_return(3);
8076 }
8077
8078
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8079 {
8080 18 fake_pack_writing=(writecycle==0);
8081
8082 //section size
8083
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8084 {
8085 new_return(4);
8086 }
8087
8088 18 writesize=0;
8089
8090 //shops
8091
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8092 {
8093 new_return(5);
8094 }
8095
8096
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8097 {
8098
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8099 {
8100 new_return(6);
8101 }
8102
8103
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8104 {
8105
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8106 {
8107 new_return(7);
8108 }
8109 480 }
8110
8111
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8112 {
8113
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8114 {
8115 new_return(8);
8116 }
8117 480 }
8118
8119
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8120 {
8121
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8122 {
8123 new_return(9);
8124 }
8125 480 }
8126 160 }
8127
8128 //infos
8129
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8130 {
8131 new_return(10);
8132 }
8133
8134
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8135 {
8136
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8137 {
8138 new_return(11);
8139 }
8140
8141
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8142 {
8143
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8144 {
8145 new_return(12);
8146 }
8147 480 }
8148
8149
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8150 {
8151
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8152 {
8153 new_return(13);
8154 }
8155 480 }
8156 160 }
8157
8158 //warp rings
8159
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8160 {
8161 new_return(14);
8162 }
8163
8164
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8165 {
8166
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8167 {
8168
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8169 {
8170 new_return(15);
8171 }
8172 1872 }
8173
8174
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8175 {
8176
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8177 {
8178 new_return(16);
8179 }
8180 1872 }
8181
8182
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8183 {
8184 new_return(17);
8185 }
8186 208 }
8187
8188 //triforce pieces
8189
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8190 {
8191
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8192 {
8193 new_return(18);
8194 }
8195 144 }
8196
8197 //end string
8198
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8199 {
8200 new_return(19);
8201 }
8202
8203 //V_MISC >= 8
8204
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8205 {
8206
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8207 {
8208
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8209 {
8210 new_return(20);
8211 }
8212 480 }
8213 160 }
8214 //V_MISC >= 9
8215
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8216 {
8217
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8218 new_return(21);
8219 576 }
8220
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8221 {
8222
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8223
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8224 new_return(22);
8225 576 }
8226 //V_MISC >= 11
8227
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8228 new_return(23);
8229
8230 //V_MISC >= 12
8231
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8232 {
8233
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8234 new_return(24);
8235 4608 }
8236
8237 //V_MISC >= 13
8238
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8239 {
8240 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8241
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8242 new_return(25);
8243
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8244 {
8245
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8246 new_return(25);
8247
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8248 new_return(25);
8249 3456 }
8250
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8251 new_return(25);
8252
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8253 new_return(25);
8254 1152 }
8255
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8256 {
8257 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8258
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8259 new_return(26);
8260
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8261 {
8262
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8263 new_return(26);
8264
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8265 new_return(26);
8266
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8267 new_return(26);
8268
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8269 new_return(26);
8270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8271 new_return(26);
8272 13824 }
8273 4608 }
8274
8275 //V_MISC >= 14
8276
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8277 {
8278
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8279 new_return(27);
8280 4608 }
8281
8282
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8283 {
8284 9 section_size=writesize;
8285 9 }
8286 18 }
8287
8288
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8289 {
8290 char ebuf[80];
8291 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8292 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8293 }
8294
8295 9 new_return(0);
8296 }
8297
8298 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8299 {
8300 //these are here to bypass compiler warnings about unused arguments
8301 9 Header=Header;
8302
8303 9 dword section_id=ID_ITEMS;
8304 9 dword section_version=V_ITEMS;
8305 // dword section_size=0;
8306 9 dword section_size = 0;
8307
8308 //section id
8309
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8310 {
8311 new_return(1);
8312 }
8313
8314 //section version info
8315
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8316 {
8317 new_return(2);
8318 }
8319
8320
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8321 {
8322 new_return(3);
8323 }
8324
8325
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8326 {
8327 18 fake_pack_writing=(writecycle==0);
8328
8329 //section size
8330
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8331 {
8332 new_return(4);
8333 }
8334
8335 18 writesize=0;
8336
8337 //finally... section data
8338
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8339 {
8340 new_return(5);
8341 }
8342
8343
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8344 {
8345
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8346 {
8347 new_return(5);
8348 }
8349 4608 }
8350
8351
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8352 {
8353
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8354 {
8355 new_return(6);
8356 }
8357
8358
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8359 {
8360 new_return(7);
8361 }
8362
8363
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8364 {
8365 new_return(8);
8366 }
8367
8368
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8369 {
8370 new_return(9);
8371 }
8372
8373
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8374 {
8375 new_return(10);
8376 }
8377
8378
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8379 {
8380 new_return(11);
8381 }
8382
8383
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8384 {
8385 new_return(12);
8386 }
8387
8388
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8389 {
8390 new_return(13);
8391 }
8392
8393
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8394 {
8395 new_return(14);
8396 }
8397
8398
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8399 {
8400 new_return(14);
8401 }
8402
8403
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8404 {
8405 new_return(15);
8406 }
8407
8408
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8409 {
8410 new_return(16);
8411 }
8412
8413
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8414 {
8415 new_return(17);
8416 }
8417
8418
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8419 {
8420 new_return(18);
8421 }
8422
8423
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8424 {
8425 new_return(19);
8426 }
8427
8428
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8429 {
8430 new_return(21);
8431 }
8432
8433
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8434 {
8435 new_return(22);
8436 }
8437
8438
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8439 {
8440 new_return(23);
8441 }
8442
8443
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8444 {
8445
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8446 {
8447 new_return(24);
8448 }
8449 36864 }
8450
8451
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8452 {
8453
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8454 {
8455 new_return(25);
8456 }
8457 9216 }
8458
8459
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8460 {
8461 new_return(26);
8462 }
8463
8464
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8465 {
8466 new_return(27);
8467 }
8468
8469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8470 {
8471 new_return(28);
8472 }
8473
8474
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8475 {
8476 new_return(29);
8477 }
8478
8479
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8480 {
8481 new_return(30);
8482 }
8483
8484
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8485 {
8486 new_return(31);
8487 }
8488
8489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8490 {
8491 new_return(32);
8492 }
8493
8494
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8495 {
8496 new_return(33);
8497 }
8498
8499
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8500 {
8501 new_return(34);
8502 }
8503
8504
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8505 {
8506 new_return(35);
8507 }
8508
8509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8510 {
8511 new_return(36);
8512 }
8513
8514
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8515 {
8516 new_return(37);
8517 }
8518
8519
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8520 {
8521 new_return(38);
8522 }
8523
8524
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8525 {
8526
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8527 {
8528 new_return(39);
8529 }
8530 9216 }
8531
8532
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8533 {
8534 new_return(40);
8535 }
8536
8537
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8538 {
8539 new_return(41);
8540 }
8541
8542
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8543 {
8544 new_return(42);
8545 }
8546
8547
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8548 {
8549 new_return(43);
8550 }
8551
8552
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8553 {
8554 new_return(44);
8555 }
8556
8557
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8558 {
8559 new_return(45);
8560 }
8561
8562
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8563 {
8564 new_return(46);
8565 }
8566
8567
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8568 {
8569 new_return(47);
8570 }
8571
8572
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8573 {
8574 new_return(48);
8575 }
8576
8577
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8578 {
8579 new_return(48);
8580 }
8581
8582 //New itemdata vars -Z
8583 //! version 27
8584
8585
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8586 {
8587 new_return(51);
8588 }
8589
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8590 {
8591 new_return(52);
8592 }
8593
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8594
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8595 {
8596 new_return(53);
8597 }
8598 46080 }
8599 //version 28
8600
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8601 {
8602 new_return(54);
8603 }
8604
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8605 {
8606
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8607 {
8608 new_return(56);
8609 }
8610 9216 }
8611
8612
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8613 {
8614 new_return(57);
8615 }
8616
8617
8618
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8619 {
8620 new_return(58);
8621 }
8622
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8623 {
8624 new_return(59);
8625 }
8626
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8627 {
8628 new_return(60);
8629 }
8630
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8631 {
8632 new_return(61);
8633 }
8634
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8635 {
8636 new_return(62);
8637 }
8638
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8639 {
8640 new_return(63);
8641 }
8642
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8643 {
8644 new_return(64);
8645 }
8646
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8647 {
8648 new_return(73);
8649 }
8650
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8651 {
8652
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8653 {
8654 new_return(74);
8655 }
8656 9216 }
8657
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8658 {
8659 new_return(75);
8660 }
8661
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8662 {
8663 new_return(76);
8664 }
8665
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8666 {
8667 new_return(77);
8668 }
8669
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8670 {
8671 new_return(81);
8672 }
8673
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8674 {
8675 new_return(82);
8676 }
8677
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8678 {
8679 new_return(83);
8680 }
8681
8682
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8683 {
8684
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8685 {
8686 new_return(84);
8687 }
8688 9216 }
8689
8690 //InitD[] labels
8691
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8692 {
8693
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8694 {
8695
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8696 {
8697 new_return(85);
8698 }
8699 2396160 }
8700
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8701 {
8702
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8703 {
8704 new_return(87);
8705 }
8706 2396160 }
8707
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8708 {
8709 new_return(88);
8710 }
8711 36864 }
8712
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8713 {
8714
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8715 {
8716 new_return(89);
8717 }
8718
8719 9216 }
8720
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8721 {
8722 new_return(90);
8723 }
8724
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8725 {
8726 new_return(91);
8727 }
8728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8729
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8730 new_return(92);
8731
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8732 new_return(95);
8733
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8734 new_return(96);
8735
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8736 new_return(97);
8737
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8738 return ret;
8739
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8740 new_return(98);
8741
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8742
8743
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8744 {
8745 9 section_size=writesize;
8746 9 }
8747 18 }
8748
8749
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8750 {
8751 char ebuf[80];
8752 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8753 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8754 }
8755
8756 9 new_return(0);
8757 9 }
8758
8759 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8760 {
8761 //these are here to bypass compiler warnings about unused arguments
8762 9 Header=Header;
8763
8764 9 dword section_id=ID_WEAPONS;
8765 9 dword section_version=V_WEAPONS;
8766 9 dword section_size = 0;
8767
8768 //section id
8769
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8770 {
8771 new_return(1);
8772 }
8773
8774 //section version info
8775
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8776 {
8777 new_return(2);
8778 }
8779
8780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8781 {
8782 new_return(3);
8783 }
8784
8785
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8786 {
8787 18 fake_pack_writing=(writecycle==0);
8788
8789 //section size
8790
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8791 {
8792 new_return(4);
8793 }
8794
8795 18 writesize=0;
8796
8797 //finally... section data
8798
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8799 {
8800 new_return(5);
8801 }
8802
8803
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8804 {
8805
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8806 {
8807 new_return(5);
8808 }
8809 4608 }
8810
8811
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8812 {
8813
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8814 {
8815 new_return(7);
8816 }
8817
8818
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8819 {
8820 new_return(8);
8821 }
8822
8823
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8824 {
8825 new_return(9);
8826 }
8827
8828
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8829 {
8830 new_return(10);
8831 }
8832
8833
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8834 {
8835 new_return(11);
8836 }
8837
8838
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8839 {
8840 new_return(12);
8841 }
8842
8843
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8844 {
8845 new_return(12);
8846 }
8847 4608 }
8848
8849
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8850 {
8851 9 section_size=writesize;
8852 9 }
8853 18 }
8854
8855
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8856 {
8857 char ebuf[80];
8858 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8859 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8860 }
8861
8862 9 new_return(0);
8863 }
8864
8865 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8866 {
8867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8868 return qe_invalid;
8869
8870 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8871 12784 bool is_0x80_screen = j >= 0x80;
8872
8873
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8874 return qe_invalid;
8875
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8876 4404 return qe_OK;
8877 //Calculate what needs writing
8878 8380 uint32_t scr_has_flags = 0;
8879
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8880
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8881 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8882
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8883 446 scr_has_flags |= SCRHAS_ITEM;
8884
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8885 28 scr_has_flags |= SCRHAS_TWARP;
8886
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8887 {
8888
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8889
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8890
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8891 {
8892 176 scr_has_flags |= SCRHAS_TWARP;
8893 176 break;
8894 }
8895 32706 }
8896
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8897
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8898 36 scr_has_flags |= SCRHAS_SWARP;
8899
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8900 {
8901
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8902
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8903
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8904 {
8905 4270 scr_has_flags |= SCRHAS_SWARP;
8906 4270 break;
8907 }
8908 16298 }
8909
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8910 44 scr_has_flags |= SCRHAS_WARPRET;
8911
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8912 {
8913
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8914 {
8915 784 scr_has_flags |= SCRHAS_WARPRET;
8916 784 break;
8917 }
8918 30208 }
8919
8920
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8921 scr_has_flags |= SCRHAS_LAYERS;
8922
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8923 {
8924
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8925
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8926 {
8927 966 scr_has_flags |= SCRHAS_LAYERS;
8928 966 break;
8929 }
8930 44532 }
8931
8932
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8933 10 scr_has_flags |= SCRHAS_MAZE;
8934
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8935 scr_has_flags |= SCRHAS_MAZE;
8936
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8937 {
8938
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8939 {
8940 scr_has_flags |= SCRHAS_MAZE;
8941 break;
8942 }
8943 33480 }
8944
8945
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8946
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8947
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8948 2968 scr_has_flags |= SCRHAS_D_S_U;
8949
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8950 {
8951
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8952 {
8953 5212 scr_has_flags |= SCRHAS_D_S_U;
8954 5212 break;
8955 }
8956 800 }
8957
8958
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8959
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8960
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8961
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8962
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8963
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8964 8380 scr_has_flags |= SCRHAS_FLAGS;
8965
8966
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8967 58 scr_has_flags |= SCRHAS_ENEMY;
8968
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8969 {
8970
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8971 {
8972 1014 scr_has_flags |= SCRHAS_ENEMY;
8973 1014 break;
8974 }
8975 73086 }
8976
8977
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
8978 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
8979 8380 scr_has_flags |= SCRHAS_CARRY;
8980
8981
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
8982 22 scr_has_flags |= SCRHAS_SCRIPT;
8983
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
8984 {
8985
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
8986 {
8987 scr_has_flags |= SCRHAS_SCRIPT;
8988 break;
8989 }
8990 66864 }
8991
8992
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
8993 {
8994
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
8995
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
8996
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
8997 {
8998 3076 scr_has_flags |= SCRHAS_SECRETS;
8999 3076 break;
9000 }
9001 680916 }
9002
9003
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9004 {
9005
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9006
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9007 {
9008 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9009 5360 break;
9010 }
9011 568532 }
9012
9013
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9014
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9015
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9016 || screen.timedwarptics || screen.screen_midi != -1
9017 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9018 8380 scr_has_flags |= SCRHAS_MISC;
9019
9020
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9021 return qe_invalid;
9022
9023 //Write stuff
9024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9025 {
9026
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9027 return qe_invalid;
9028
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9029 return qe_invalid;
9030
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9031 return qe_invalid;
9032
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9033 return qe_invalid;
9034
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9035 return qe_invalid;
9036
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9037 return qe_invalid;
9038
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9039 return qe_invalid;
9040 8380 }
9041
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9042 {
9043
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9044 return qe_invalid;
9045
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9046 return qe_invalid;
9047
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9048 return qe_invalid;
9049
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9050 return qe_invalid;
9051 446 }
9052
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9053 {
9054
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9055 return qe_invalid;
9056 4374 }
9057
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9058 {
9059
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9060 {
9061
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9062 return qe_invalid;
9063 816 }
9064
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9065 {
9066
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9067 return qe_invalid;
9068 816 }
9069
9070
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9071 {
9072
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9073 return qe_invalid;
9074 816 }
9075
9076
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9077 return qe_invalid;
9078 204 }
9079
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9080 {
9081
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9082 {
9083
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9084 return qe_invalid;
9085 17224 }
9086
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9087 {
9088
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9089 return qe_invalid;
9090 17224 }
9091
9092
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9093 {
9094
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9095 return qe_invalid;
9096 17224 }
9097
9098
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9099 return qe_invalid;
9100
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9101 return qe_invalid;
9102 4306 }
9103
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9104 {
9105
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9106 {
9107
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9108 return qe_invalid;
9109 3312 }
9110
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9111 {
9112
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9113 return qe_invalid;
9114 3312 }
9115
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9116 return qe_invalid;
9117
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9118 return qe_invalid;
9119 828 }
9120
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9121 {
9122
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9123 {
9124
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9125 return qe_invalid;
9126 5796 }
9127
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9128 {
9129
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9130 return qe_invalid;
9131 5796 }
9132
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9133 {
9134
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9135 return qe_invalid;
9136 5796 }
9137
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9138 return qe_invalid;
9139
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9140 return qe_invalid;
9141 966 }
9142
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9143 {
9144
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9145 {
9146
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9147 return qe_invalid;
9148 40 }
9149
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9150 return qe_invalid;
9151
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9152 return qe_invalid;
9153 10 }
9154
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9155 {
9156
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9157 return qe_invalid;
9158
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9159 {
9160
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9161 return qe_invalid;
9162 32720 }
9163
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9164 return qe_invalid;
9165
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9166 return qe_invalid;
9167
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9168 return qe_invalid;
9169
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9170 return qe_invalid;
9171 8180 }
9172
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9173 {
9174
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9175 return qe_invalid;
9176
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9177 return qe_invalid;
9178
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9179 return qe_invalid;
9180
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9181 return qe_invalid;
9182
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9183 return qe_invalid;
9184
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9185 return qe_invalid;
9186
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9187 return qe_invalid;
9188
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9189 return qe_invalid;
9190
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9191 return qe_invalid;
9192
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9193 return qe_invalid;
9194
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9195 return qe_invalid;
9196 1294 }
9197
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9198 {
9199
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9200 {
9201
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9202 return qe_invalid;
9203 10720 }
9204
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9205 return qe_invalid;
9206 1072 }
9207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9208 {
9209
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9210 return qe_invalid;
9211
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9212 return qe_invalid;
9213
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9214 return qe_invalid;
9215
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9216 return qe_invalid;
9217
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9218 return qe_invalid;
9219
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9220 return qe_invalid;
9221 8380 }
9222
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9223 {
9224
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9225 return qe_invalid;
9226
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9227 return qe_invalid;
9228
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9229 {
9230
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9231 return qe_invalid;
9232 176 }
9233 22 }
9234
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9235 {
9236
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9237 {
9238
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9239 return qe_invalid;
9240 393728 }
9241
9242
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9243 {
9244
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9245 return qe_invalid;
9246 393728 }
9247
9248
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9249 {
9250
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9251 return qe_invalid;
9252 393728 }
9253 3076 }
9254
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9255 {
9256
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9257 {
9258
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9259 return qe_invalid;
9260 943360 }
9261
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9262 {
9263
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9264 return qe_invalid;
9265 943360 }
9266
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9267 {
9268
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9269 return qe_invalid;
9270 943360 }
9271 5360 }
9272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9273 {
9274
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9275 return qe_invalid;
9276
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9277 return qe_invalid;
9278
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9279 return qe_invalid;
9280
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9281 return qe_invalid;
9282
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9283 return qe_invalid;
9284
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9285 return qe_invalid;
9286
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9287 return qe_invalid;
9288
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9289 return qe_invalid;
9290
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9291 return qe_invalid;
9292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9293 return qe_invalid;
9294
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9295 return qe_invalid;
9296 8380 }
9297
9298 8380 dword numffc = screen.numFFC();
9299
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9300 return qe_invalid;
9301
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9302 {
9303 245678 ffcdata const& tempffc = screen.ffcs[k];
9304
9305
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9306 return qe_invalid;
9307
9308
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9309 243364 continue;
9310
9311
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9312 return qe_invalid;
9313
9314
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9315 return qe_invalid;
9316
9317
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9318 return qe_invalid;
9319
9320
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9321 return qe_invalid;
9322
9323
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9324 return qe_invalid;
9325
9326
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9327 return qe_invalid;
9328
9329
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9330 return qe_invalid;
9331
9332
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9333 return qe_invalid;
9334
9335
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9336 return qe_invalid;
9337
9338
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9339 return qe_invalid;
9340
9341
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9342 return qe_invalid;
9343
9344
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9345 return qe_invalid;
9346
9347
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9348 return qe_invalid;
9349
9350
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9351 return qe_invalid;
9352
9353
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9354 return qe_invalid;
9355
9356
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9357 {
9358
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9359 return qe_invalid;
9360 18512 }
9361
9362
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9363 return qe_invalid;
9364 2314 }
9365
9366
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9367 return qe_invalid;
9368
9369
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9370 {
9371
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9372 return qe_invalid;
9373
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9374 return qe_invalid;
9375 6 }
9376
9377 8380 return qe_OK;
9378 12784 }
9379
9380 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9381 {
9382 9 dword section_id=ID_MAPS;
9383 9 dword section_version=V_MAPS;
9384 9 dword section_size = 0;
9385
9386 //section id
9387
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9388 {
9389 new_return(1);
9390 }
9391
9392 //section version info
9393
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9394 {
9395 new_return(2);
9396 }
9397
9398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9399 {
9400 new_return(3);
9401 }
9402
9403
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9404 {
9405 18 fake_pack_writing=(writecycle==0);
9406
9407 //section size
9408
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9409 {
9410 new_return(4);
9411 }
9412
9413 18 writesize=0;
9414
9415
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9416 {
9417 new_return(5);
9418 }
9419 18 map_infos.resize(map_count);
9420
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9421 {
9422 100 byte valid = 0;
9423
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9424 {
9425
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9426 break;
9427 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9428
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9429 {
9430 94 valid = 1;
9431 94 break;
9432 }
9433 1188 }
9434
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9435 {
9436 new_return(6);
9437 }
9438
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9439
9440 { //per-map info
9441 94 auto const& mapinf = map_infos[i];
9442
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9443 {
9444
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9445 new_return(7);
9446 564 }
9447
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9448 new_return(9);
9449
9450
9451
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9452 {
9453
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9454 {
9455
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9456 {
9457 new_return(8);
9458 }
9459 6016 }
9460 752 }
9461 }
9462
9463
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9464 12784 writemapscreen(f,i,j);
9465 94 }
9466
9467
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9468 {
9469 9 section_size=writesize;
9470 9 }
9471 18 }
9472
9473
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9474 {
9475 char ebuf[80];
9476 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9477 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9478 }
9479
9480 9 new_return(0);
9481 }
9482
9483 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9484 {
9485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9486 return 22;
9487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9488 return 22;
9489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9490 return 23;
9491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9492 return 34;
9493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9494 return 35;
9495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9496 return 36;
9497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9498 return 37;
9499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9500 return 38;
9501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9502 return 39;
9503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9504 return 40;
9505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9506 return 41;
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9508 return 42;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9510 return 43;
9511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9512 return 44;
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9514 return 45;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9516 return 46;
9517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9518 return 47;
9519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9520 return 48;
9521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9522 return 49;
9523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9524 return 50;
9525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9526 return 51;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9528 return 52;
9529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9530 return 53;
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9532 return 69;
9533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9534 return 70;
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9536 return 71;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9538 return 72;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9540 return 76;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9542 return 77;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9544 return 89;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9546 return 90;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9548 return 91;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9550 return 92;
9551
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9553 return 93;
9554
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9555 return 94;
9556
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9557 return 95;
9558
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9559 return 96;
9560
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9561 return 97;
9562
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9563 return 98;
9564
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9565 return 99;
9566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9567 return 100;
9568
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9569 return 101;
9570
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9571 return 102;
9572
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9573 return 103;
9574
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9575 return 104;
9576
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9577 return 105;
9578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9579 return 106;
9580
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9581 return 107;
9582
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9583 return 108;
9584
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9585 return 109;
9586
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9587 return 110;
9588
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9589 return 111;
9590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9591 return 112;
9592
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9593 return 113;
9594
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9595 return 114;
9596
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9597 return 115;
9598
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9599 return 116;
9600
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9601 return 117;
9602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9603 return 118;
9604
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9605 return 119;
9606
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9607 return 120;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9609 return 121;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9611 return 122;
9612
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9613 return 123;
9614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9615 return 124;
9616
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9617 return 125;
9618
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9619 return 126;
9620 460 return 0;
9621 460 }
9622 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9623 {
9624 //Check what needs writing
9625 258906 word combo_has_flags = 0;
9626
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9627 {
9628
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9629
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9630 {
9631 3190 combo_has_flags |= CHAS_ATTRIB;
9632 3190 break;
9633 }
9634 2052960 }
9635
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9636 460 combo_has_flags |= CHAS_TRIG;
9637
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9638 298 combo_has_flags |= CHAS_FLAG;
9639
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9640
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9641
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9642 28174 combo_has_flags |= CHAS_ANIM;
9643
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9644 6 combo_has_flags |= CHAS_SCRIPT;
9645
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9646 {
9647
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9648 {
9649 combo_has_flags |= CHAS_SCRIPT;
9650 break;
9651 }
9652 2071200 }
9653
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9654
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9655 82514 combo_has_flags |= CHAS_BASIC;
9656
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9657
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9658
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9659
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9660
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9661
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9662
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9663 10 combo_has_flags |= CHAS_LIFT;
9664
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9665
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9666
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9667
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9668
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9669
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9670 258906 combo_has_flags |= CHAS_GENERAL;
9671
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9672 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9673
9674
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9675 {
9676 return 50;
9677 }
9678
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9679 //Write the combo
9680
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9681 {
9682
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9683 return 6;
9684
9685
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9686 return 7;
9687
9688
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9689 return 8;
9690
9691
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9692 return 9;
9693
9694
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9695 return 15;
9696
9697
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9698 return 10;
9699 82514 }
9700
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9701 {
9702 6 p_putcstr(tmp_cmb.label, f);
9703
9704
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9705 return 26;
9706
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9707
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9708 return 27;
9709 6 }
9710
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9711 {
9712
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9713 return 11;
9714
9715
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9716 return 12;
9717
9718
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9719 return 13;
9720
9721
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9722 return 14;
9723
9724
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9725 return 16;
9726
9727
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9728 return 18;
9729
9730
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9731 return 19;
9732 28174 }
9733
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9734 {
9735
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9736
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9737 return 20;
9738
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9739
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9740 return 25;
9741
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9742
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9743 return 32;
9744 3190 }
9745
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9746 {
9747
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9748 return 21;
9749
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9750 return 33;
9751 298 }
9752
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9753 {
9754
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9755
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9756 return 34;
9757
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9758 {
9759 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9760
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9761 460 }
9762
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9763 return 35;
9764 460 }
9765
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9766 {
9767
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9768 return 54;
9769
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9770 return 55;
9771
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9772 return 56;
9773
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9774 return 57;
9775
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9776 return 58;
9777
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9778 return 59;
9779
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9780 return 60;
9781
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9782 return 61;
9783
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9784 return 62;
9785
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9786 return 63;
9787
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9788 return 64;
9789
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9790 return 65;
9791
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9792 return 66;
9793
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9794 return 67;
9795
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9796 return 68;
9797
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9798 return 78;
9799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9800 return ret;
9801 258906 }
9802
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9803 {
9804
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9805 return 73;
9806
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9807 return 74;
9808
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9809 return 75;
9810
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9811 return 79;
9812
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9813 return 80;
9814
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9815 return 81;
9816
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9817 return 82;
9818
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9819 return 83;
9820
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9821 return 84;
9822
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9823 return 85;
9824
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9825 return 86;
9826
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9827 return 87;
9828
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9829 return 88;
9830
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9831 return 89;
9832
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9833 return 90;
9834
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9835 return 91;
9836
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9837 return 92;
9838
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9839 return 93;
9840
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9841 return 94;
9842
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9843 return 95;
9844
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9845 return 96;
9846
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9847 return 97;
9848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9849 return 98;
9850 2200 }
9851
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9852 {
9853 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9854 return ret;
9855 }
9856 258906 return 0;
9857 258906 }
9858
9859 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9860 {
9861 //these are here to bypass compiler warnings about unused arguments
9862 9 version=version;
9863 9 build=build;
9864
9865 word combos_used;
9866 9 dword section_id=ID_COMBOS;
9867 9 dword section_version=V_COMBOS;
9868 // dword section_size=0;
9869 9 combos_used = count_combos()-start_combo;
9870
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9871
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9872 9 dword section_size = 0;
9873
9874 //section id
9875
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9876 {
9877 new_return(1);
9878 }
9879
9880 //section version info
9881
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9882 {
9883 new_return(2);
9884 }
9885
9886
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9887 {
9888 new_return(3);
9889 }
9890
9891
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9892 {
9893 18 fake_pack_writing=(writecycle==0);
9894
9895 //section size
9896
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9897 {
9898 new_return(4);
9899 }
9900
9901 18 writesize=0;
9902
9903 //finally... section data
9904 18 combos_used=count_combos()-start_combo;
9905
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9906
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9907
9908
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9909 {
9910 new_return(5);
9911 }
9912
9913 18 size_t end_combo = start_combo+combos_used;
9914
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9915 {
9916 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9917
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9918 258906 }
9919
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9920 {
9921 9 section_size=writesize;
9922 9 }
9923 18 }
9924
9925
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9926 {
9927 char ebuf[80];
9928 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9929 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9930 }
9931
9932 9 new_return(0);
9933 9 }
9934
9935 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9936 {
9937 //these are here to bypass compiler warnings about unused arguments
9938 9 version=version;
9939 9 build=build;
9940
9941 9 dword section_id=ID_COMBOALIASES;
9942 9 dword section_version=V_COMBOALIASES;
9943 9 dword section_size=0;
9944
9945 //section id
9946
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9947 {
9948 new_return(1);
9949 }
9950
9951 //section version info
9952
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9953 {
9954 new_return(2);
9955 }
9956
9957
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9958 {
9959 new_return(3);
9960 }
9961
9962
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9963 {
9964 18 fake_pack_writing=(writecycle==0);
9965
9966 //section size
9967
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9968 {
9969 new_return(4);
9970 }
9971
9972 18 writesize=0;
9973
9974 //finally... section data
9975
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9976 {
9977
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9978 {
9979 new_return(5);
9980 }
9981
9982
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9983 {
9984 new_return(6);
9985 }
9986
9987 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9988
9989
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
9990 {
9991 new_return(7);
9992 }
9993
9994
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
9995 {
9996 new_return(8);
9997 }
9998
9999
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10000 {
10001 new_return(9);
10002 }
10003
10004
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10005 {
10006
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10007 {
10008 new_return(10);
10009 }
10010 149596 }
10011
10012
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10013 {
10014
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10015 {
10016 new_return(11);
10017 }
10018 149596 }
10019 147456 }
10020
10021 //Combo pools!
10022 int16_t num_cpools;
10023
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10024 {
10025
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10026 {
10027 2 ++num_cpools;
10028 2 break;
10029 }
10030 147450 }
10031
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10032
10033
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10034 {
10035 new_return(12);
10036 }
10037
10038
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10039 {
10040 6 combo_pool const& pool = combo_pools[cp];
10041 6 int32_t num_combos = pool.combos.size();
10042
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10043 {
10044 new_return(13);
10045 }
10046
10047
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10048 {
10049 26 cpool_entry const& entry = pool.combos.at(q);
10050
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10051 {
10052 new_return(14);
10053 }
10054
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10055 {
10056 new_return(15);
10057 }
10058
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10059 {
10060 new_return(16);
10061 }
10062 26 }
10063 6 }
10064
10065 //Autocombos!
10066 int16_t num_cautos;
10067
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10068 {
10069
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10070 {
10071 ++num_cautos;
10072 break;
10073 }
10074 147456 }
10075
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10076
10077
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10078 {
10079 new_return(17);
10080 }
10081
10082
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10083 {
10084 combo_auto const& cauto = combo_autos[ca];
10085 if (!p_putc(cauto.getType(), f))
10086 {
10087 new_return(18);
10088 }
10089 if (!p_iputl(cauto.getIconDisplay(), f))
10090 {
10091 new_return(19);
10092 }
10093 if (!p_iputl(cauto.getEraseCombo(), f))
10094 {
10095 new_return(20);
10096 }
10097 if (!p_putc(cauto.getFlags(), f))
10098 {
10099 new_return(21);
10100 }
10101 if (!p_putc(cauto.getArg(), f))
10102 {
10103 new_return(22);
10104 }
10105 int32_t num_combos = cauto.combos.size();
10106 if (!p_iputl(num_combos, f))
10107 {
10108 new_return(23);
10109 }
10110
10111 for (auto q = 0; q < num_combos; ++q)
10112 {
10113 autocombo_entry const& entry = cauto.combos.at(q);
10114 if (!p_putc(entry.ctype, f))
10115 {
10116 new_return(24);
10117 }
10118 if (!p_iputl(entry.cid, f))
10119 {
10120 new_return(25);
10121 }
10122 }
10123 }
10124
10125
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10126 {
10127 9 section_size=writesize;
10128 9 }
10129 18 }
10130
10131
10132
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10133 {
10134 char ebuf[80];
10135 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10136 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10137 }
10138
10139 9 new_return(0);
10140 }
10141
10142 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10143 {
10144 //these are here to bypass compiler warnings about unused arguments
10145 9 version=version;
10146 9 build=build;
10147 9 start_cset=start_cset;
10148 9 max_csets=max_csets;
10149
10150 9 dword section_id=ID_CSETS;
10151 9 dword section_version=V_CSETS;
10152 9 int32_t palcycles = count_palcycles(&QMisc);
10153 // int32_t palcyccount = count_palcycles(&QMisc);
10154 9 dword section_size = 0;
10155
10156 //section id
10157
10158
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10159 {
10160 new_return(1);
10161 }
10162
10163 //section version info
10164
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10165 {
10166 new_return(2);
10167 }
10168
10169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10170 {
10171 new_return(3);
10172 }
10173
10174
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10175 {
10176 18 fake_pack_writing=(writecycle==0);
10177
10178 //section size
10179
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10180 {
10181 new_return(4);
10182 }
10183
10184 18 writesize=0;
10185
10186 //finally... section data
10187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10188 {
10189 new_return(5);
10190 }
10191
10192
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10193 {
10194 new_return(6);
10195 }
10196
10197
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10198 {
10199 new_return(15);
10200 }
10201
10202
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10203 {
10204
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10205 {
10206
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10207 {
10208 new_return(16);
10209 }
10210 1650 }
10211
10212
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10213 {
10214
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10215 {
10216 new_return(17);
10217 }
10218 1650 }
10219
10220
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10221 {
10222
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10223 {
10224 new_return(18);
10225 }
10226 1650 }
10227 550 }
10228
10229
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10230 {
10231 9 section_size=writesize;
10232 9 }
10233 18 }
10234
10235
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10236 {
10237 char ebuf[80];
10238 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10239 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10240 }
10241
10242 9 new_return(0);
10243 }
10244
10245 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10246 {
10247 //these are here to bypass compiler warnings about unused arguments
10248 9 version=version;
10249 9 build=build;
10250 9 start_msgstr=start_msgstr;
10251 9 max_msgstrs=max_msgstrs;
10252
10253 9 dword section_id=ID_STRINGS;
10254 9 dword section_version=V_STRINGS;
10255 9 dword section_size = 0;
10256
10257 //section id
10258
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10259 {
10260 new_return(1);
10261 }
10262
10263 //section version info
10264
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10265 {
10266 new_return(2);
10267 }
10268
10269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10270 {
10271 new_return(3);
10272 }
10273
10274
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10275 {
10276 18 fake_pack_writing=(writecycle==0);
10277
10278 //section size
10279
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10280 {
10281 new_return(4);
10282 }
10283
10284 18 writesize=0;
10285
10286 //finally... section data
10287
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10288 {
10289 return qe_invalid;
10290 }
10291
10292
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10293 {
10294 836 int32_t sz = MsgStrings[i].s.size();
10295
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10296
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10297 {
10298 return qe_invalid;
10299 }
10300
10301 836 char const* tmpstr = MsgStrings[i].s.c_str();
10302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10303 {
10304
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10305 {
10306 return qe_invalid;
10307 }
10308 836 }
10309
10310
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10311 {
10312 return qe_invalid;
10313 }
10314
10315
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10316 {
10317 return qe_invalid;
10318 }
10319
10320
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10321 {
10322 return qe_invalid;
10323 }
10324
10325
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10326 {
10327 return qe_invalid;
10328 }
10329
10330
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10331 {
10332 return qe_invalid;
10333 }
10334
10335
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10336 {
10337 return qe_invalid;
10338 }
10339
10340
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10341 {
10342 return qe_invalid;
10343 }
10344
10345
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10346 {
10347 return qe_invalid;
10348 }
10349
10350
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10351 {
10352 return qe_invalid;
10353 }
10354
10355
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10356 {
10357 return qe_invalid;
10358 }
10359
10360
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10361 {
10362 return qe_invalid;
10363 }
10364
10365
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10366 {
10367 return qe_invalid;
10368 }
10369
10370
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10371 {
10372
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10373 {
10374 return qe_invalid;
10375 }
10376 3344 }
10377
10378
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10379 {
10380 return qe_invalid;
10381 }
10382
10383
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10384 {
10385 return qe_invalid;
10386 }
10387
10388
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10389 {
10390 return qe_invalid;
10391 }
10392
10393
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10394 {
10395 return qe_invalid;
10396 }
10397
10398
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10399 {
10400 return qe_invalid;
10401 }
10402
10403
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10404 {
10405 return qe_invalid;
10406 }
10407
10408
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10409 {
10410 return qe_invalid;
10411 }
10412
10413
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10414 {
10415 return qe_invalid;
10416 }
10417
10418
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10419 {
10420 return qe_invalid;
10421 }
10422
10423
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10424 {
10425 return qe_invalid;
10426 }
10427
10428
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10429 {
10430 return qe_invalid;
10431 }
10432 836 }
10433
10434
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10435 {
10436 9 section_size=writesize;
10437 9 }
10438 18 }
10439
10440
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10441 {
10442 char ebuf[80];
10443 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10444 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10445 }
10446
10447 9 new_return(0);
10448 9 }
10449
10450 int32_t writestrings_text(PACKFILE *f)
10451 {
10452 std::map<int32_t, int32_t> msglistcache;
10453
10454 for(int32_t index = 1; index<msg_count; index++)
10455 {
10456 for(int32_t i=1; i<msg_count; i++)
10457 {
10458 if(MsgStrings[i].listpos==index)
10459 {
10460 msglistcache[index-1]=i;
10461 break;
10462 }
10463 }
10464 }
10465
10466 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10467 {
10468 fake_pack_writing=(writecycle==0);
10469 char ebuf[32];
10470
10471 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10472
10473 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10474 {
10475 return qe_invalid;
10476 }
10477
10478 for(int32_t i=1; i<msg_count; i++)
10479 {
10480 int32_t str = msglistcache[i-1];
10481
10482 if(!str)
10483 continue;
10484
10485 if(MsgStrings[str].nextstring != 0)
10486 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10487 else
10488 sprintf(ebuf,"\n\n___%d___\n", str);
10489
10490 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10491 {
10492 return qe_invalid;
10493 }
10494
10495 std::string text = MsgStrings[str].serialize();
10496 if (!pfwrite(text.c_str(), text.size(), f))
10497 {
10498 return qe_invalid;
10499 }
10500 }
10501 }
10502
10503 new_return(0);
10504 }
10505
10506 1 int32_t writestrings_tsv(PACKFILE *f)
10507 {
10508 1 std::stringstream ss;
10509
10510
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10511
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10512
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10520
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10521
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10522
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10523
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10524
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10526
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10527
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10529
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10530
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10531
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10532
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10533
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10534
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10535
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10536 };
10537
10538
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10539 {
10540
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10541
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10542 1 break;
10543
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10544 }
10545
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10546
10547 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10548
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10549
10550
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10551 {
10552 35 auto& msg = MsgStrings[i];
10553
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10554 {
10555
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10556
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10557
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10558 35 break;
10559
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10560
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10561
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10562 35 }
10563
10564
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10565
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10566 {
10567 return qe_invalid;
10568 }
10569
10570 1 new_return(0);
10571 1 }
10572
10573 std::string parse_to_legacy_msg_str_encoding(std::string const& s);
10574
10575 void parse_strings_tsv(std::string tsv)
10576 {
10577 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10578 { "message", [](auto& msg, auto& text){ msg.setFromLegacyEncoding(parse_to_legacy_msg_str_encoding(text)); } },
10579 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10580 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10581 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10582 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10583 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10584 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10585 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10586 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10587 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10588 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10589 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10590 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10591 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10592 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10593 { "margin", [&](auto& msg, auto& text){
10594 std::vector<std::string> strs;
10595 util::split(text, strs, ' ');
10596 if (strs.size() != 4)
10597 throw std::runtime_error("margin field must have 4 components");
10598 msg.margins[0] = std::stoi(strs[0]);
10599 msg.margins[1] = std::stoi(strs[1]);
10600 msg.margins[2] = std::stoi(strs[2]);
10601 msg.margins[3] = std::stoi(strs[3]);
10602 } },
10603 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10604 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10605 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10606 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10607 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10608 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10609 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10610 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10611 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10612 };
10613
10614 std::vector<std::string> rows;
10615 util::split(tsv, rows, '\n');
10616 if (rows.size())
10617 {
10618 std::string last = rows.back();
10619 util::trimstr(last);
10620 if (last.empty())
10621 rows.pop_back();
10622 }
10623 if (rows.size() <= 1)
10624 throw std::runtime_error("missing header row");
10625
10626 std::vector<std::string> columns;
10627 util::split(rows[0], columns, '\t');
10628 for (auto name : columns)
10629 {
10630 if (!fields.contains(name))
10631 throw std::runtime_error(fmt::format("invalid field: {}", name));
10632 }
10633
10634 int start_index = 1;
10635 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10636 start_index += 1;
10637
10638 int num_strings = rows.size() - start_index + 1;
10639 if (num_strings > MAXMSGS-1)
10640 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10641
10642 std::vector<MsgStr> msgs;
10643 msgs.reserve(num_strings);
10644 for (int i = start_index; i < rows.size(); i++)
10645 {
10646 std::vector<std::string> strs;
10647 util::split(rows[i], strs, '\t');
10648 if (strs.size() != columns.size())
10649 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10650
10651 int j = 0;
10652 auto& msg = msgs.emplace_back();
10653 for (auto& name : columns)
10654 {
10655 auto& fn = fields[name];
10656 try
10657 {
10658 fn(msg, strs[j++]);
10659 }
10660 catch (std::exception& ex)
10661 {
10662 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10663 }
10664 }
10665 }
10666
10667 init_msgstrings(0, msgs.size());
10668 for (int i = 0; i < msgs.size(); i++)
10669 MsgStrings[i + 1] = msgs[i];
10670 msg_count = msgs.size() + 1;
10671 msglistcache.clear();
10672 }
10673
10674 bool isblanktile(tiledata *buf, int32_t i);
10675 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10676 {
10677 //these are here to bypass compiler warnings about unused arguments
10678 9 version=version;
10679 9 build=build;
10680
10681 int32_t tiles_used;
10682 9 dword section_id=ID_TILES;
10683 9 dword section_version=V_TILES;
10684 9 al_trace("Counting tiles used\n");
10685 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10686
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10687
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10688 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10689 9 dword section_size = 0;
10690
10691 //section id
10692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10693 {
10694 new_return(1);
10695 }
10696
10697 //section version info
10698
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10699 {
10700 new_return(2);
10701 }
10702
10703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10704 {
10705 new_return(3);
10706 }
10707
10708
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10709 {
10710 18 fake_pack_writing=(writecycle==0);
10711
10712 //section size
10713
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10714 {
10715 new_return(4);
10716 }
10717
10718 18 writesize=0;
10719
10720 //finally... section data
10721 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10722
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10723
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10724
10725
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10726 {
10727 new_return(5);
10728 }
10729
10730
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10731 {
10732
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10733 {
10734
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10735 new_return(8);
10736 365770 }
10737 else
10738 {
10739 330614 int format = newtilebuf[start_tile+i].format;
10740
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10741 {
10742 new_return(6);
10743 }
10744
10745
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10746 {
10747 byte temp_tile[128];
10748 327742 byte *di = temp_tile;
10749 327742 byte *src = newtilebuf[start_tile+i].data;
10750
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10751 {
10752 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10753 41950976 ++di;
10754 41950976 }
10755
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10756 {
10757 new_return(7);
10758 }
10759 327742 }
10760
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10761 {
10762 new_return(7);
10763 }
10764 }
10765 696384 }
10766
10767
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10768 {
10769 9 section_size=writesize;
10770 9 }
10771 18 }
10772
10773
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10774 {
10775 char ebuf[80];
10776 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10777 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10778 }
10779
10780 9 new_return(0);
10781 }
10782
10783 /* MIDI Format
10784 section_id LONG
10785 section_version WORD
10786 section_cversion WORD
10787 section_size LONG
10788 midi_flags 32 Byte ? BITFIELD[252]
10789
10790 [
10791 title 36
10792 start 4
10793 loop_start 4
10794 loop_end 4
10795 loop 2
10796 volume 2
10797 midi *
10798 ]
10799
10800 */
10801
10802 9 int32_t writemidis(PACKFILE *f)
10803 {
10804 9 dword section_id=ID_MIDIS;
10805 9 dword section_version=V_MIDIS;
10806 9 dword section_size = 0;
10807
10808 //section id
10809
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10810 {
10811 new_return(1);
10812 }
10813
10814 //section version info
10815
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10816 {
10817 new_return(2);
10818 }
10819
10820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10821 {
10822 new_return(3);
10823 }
10824
10825
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10826 {
10827 18 fake_pack_writing=(writecycle==0);
10828
10829 //section size
10830
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10831 {
10832 new_return(4);
10833 }
10834
10835 18 writesize=0;
10836
10837 //finally... section data
10838
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10839 {
10840 new_return(5);
10841 }
10842
10843
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10844 {
10845
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10846 {
10847
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10848 {
10849 new_return(6);
10850 }
10851
10852
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10853 {
10854 new_return(7);
10855 }
10856
10857
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10858 {
10859 new_return(8);
10860 }
10861
10862
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10863 {
10864 new_return(9);
10865 }
10866
10867
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10868 {
10869 new_return(10);
10870 }
10871
10872
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10873 {
10874 new_return(11);
10875 }
10876
10877
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10878 {
10879 new_return(12);
10880 }
10881
10882 130 byte format = MFORMAT_MIDI;
10883
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10884 {
10885 new_return(13);
10886 }
10887
10888
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10889 130 }
10890 4536 }
10891
10892
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10893 {
10894 9 section_size=writesize;
10895 9 }
10896 18 }
10897
10898
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10899 {
10900 char ebuf[80];
10901 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10902 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10903 }
10904
10905 9 new_return(0);
10906 }
10907
10908 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10909 {
10910 9 dword section_id=ID_CHEATS;
10911 9 dword section_version=V_CHEATS;
10912 9 dword section_size = 0;
10913
10914 //section id
10915
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10916 {
10917 new_return(1);
10918 }
10919
10920 //section version info
10921
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10922 {
10923 new_return(2);
10924 }
10925
10926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10927 {
10928 new_return(3);
10929 }
10930
10931
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10932 {
10933 18 fake_pack_writing=(writecycle==0);
10934
10935 //section size
10936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10937 {
10938 new_return(4);
10939 }
10940
10941 18 writesize=0;
10942
10943 //finally... section data
10944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10945 {
10946 new_return(5);
10947 }
10948
10949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10950 {
10951
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10952 {
10953 new_return(6);
10954 }
10955
10956
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10957 {
10958 new_return(7);
10959 }
10960 18 }
10961
10962
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10963 {
10964 9 section_size=writesize;
10965 9 }
10966 18 }
10967
10968
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10969 {
10970 char ebuf[80];
10971 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10972 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10973 }
10974
10975 9 new_return(0);
10976 }
10977
10978 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10979 {
10980 //these are here to bypass compiler warnings about unused arguments
10981 9 Header=Header;
10982
10983 9 dword section_id=ID_GUYS;
10984 9 dword section_version=V_GUYS;
10985 9 dword section_size=0;
10986
10987 //section id
10988
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10989 {
10990 new_return(1);
10991 }
10992
10993 //section version info
10994
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10995 {
10996 new_return(2);
10997 }
10998
10999
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11000 {
11001 new_return(3);
11002 }
11003
11004
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11005 {
11006 18 fake_pack_writing=(writecycle==0);
11007
11008 //section size
11009
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11010 {
11011 new_return(4);
11012 }
11013
11014 18 writesize=0;
11015
11016 //finally... section data
11017
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11018 {
11019
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11020 {
11021 new_return(5);
11022 }
11023 9216 }
11024
11025
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11026 {
11027 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11028 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11029
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11030 {
11031 new_return(6);
11032 }
11033
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11034 {
11035 new_return(7);
11036 }
11037
11038
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11039 {
11040 new_return(8);
11041 }
11042
11043
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11044 {
11045 new_return(9);
11046 }
11047
11048
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11049 {
11050 new_return(10);
11051 }
11052
11053
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11054 {
11055 new_return(11);
11056 }
11057
11058
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11059 {
11060 new_return(12);
11061 }
11062
11063
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11064 {
11065 new_return(13);
11066 }
11067
11068
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11069 {
11070 new_return(14);
11071 }
11072
11073
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11074 {
11075 new_return(15);
11076 }
11077
11078
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11079 {
11080 new_return(16);
11081 }
11082
11083
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11084 {
11085 new_return(17);
11086 }
11087
11088
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11089 {
11090 new_return(18);
11091 }
11092
11093
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11094 {
11095 new_return(19);
11096 }
11097
11098
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11099 {
11100 new_return(20);
11101 }
11102
11103
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11104 {
11105 new_return(21);
11106 }
11107
11108
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11109 {
11110 new_return(22);
11111 }
11112
11113
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11114 {
11115 new_return(23);
11116 }
11117
11118
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11119 {
11120 new_return(24);
11121 }
11122
11123
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11124 {
11125 new_return(25);
11126 }
11127
11128
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11129 {
11130 new_return(26);
11131 }
11132
11133
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11134 {
11135 new_return(27);
11136 }
11137
11138
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11139 {
11140 new_return(28);
11141 }
11142
11143
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11144 {
11145 new_return(29);
11146 }
11147
11148
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11149 {
11150 new_return(30);
11151 }
11152
11153
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11154 {
11155 new_return(31);
11156 }
11157
11158
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11159 {
11160 new_return(32);
11161 }
11162
11163
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11164 {
11165 new_return(33);
11166 }
11167
11168
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11169 {
11170 new_return(34);
11171 }
11172
11173
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11174 {
11175 new_return(35);
11176 }
11177
11178
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11179 {
11180 new_return(36);
11181 }
11182
11183
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11184 {
11185 new_return(37);
11186 }
11187
11188
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11189 {
11190 new_return(38);
11191 }
11192
11193
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11194 {
11195 new_return(39);
11196 }
11197
11198
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11199 {
11200 new_return(40);
11201 }
11202
11203
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11204 {
11205 new_return(41);
11206 }
11207
11208
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11209 {
11210 new_return(42);
11211 }
11212
11213
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11214 {
11215 new_return(43);
11216 }
11217
11218
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11219 {
11220 new_return(44);
11221 }
11222
11223
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11224 {
11225 new_return(45);
11226 }
11227
11228
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11229 {
11230
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11231 {
11232 new_return(46);
11233 }
11234 175104 }
11235
11236
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11237 {
11238 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11240 //Force SFX_HIT here.
11241
11242 2048 }
11243
11244
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11245 {
11246 new_return(47);
11247 }
11248
11249
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11250 {
11251 new_return(48);
11252 }
11253
11254
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11255 {
11256 new_return(49);
11257 }
11258
11259
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11260 {
11261 new_return(50);
11262 }
11263
11264 //New 2.6 defences
11265
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11266 {
11267
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11268 {
11269 new_return(51);
11270 }
11271 202752 }
11272
11273 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11274
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11275 {
11276 new_return(52);
11277 }
11278
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11279 {
11280 new_return(53);
11281 }
11282
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11283 {
11284 new_return(54);
11285 }
11286
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11287 {
11288 new_return(55);
11289 }
11290
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11291 {
11292 new_return(56);
11293 }
11294 // These are not fixed types, but ints, so they are safe to use here.
11295
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11296 {
11297 new_return(57);
11298 }
11299
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11300 {
11301 new_return(58);
11302 }
11303
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11304 {
11305 new_return(59);
11306 }
11307
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11308 {
11309 new_return(60);
11310 }
11311
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11312 {
11313 new_return(61);
11314 }
11315
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11316 {
11317 new_return(62);
11318 }
11319
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11320 {
11321 new_return(63);
11322 }
11323
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11324 {
11325 new_return(64);
11326 }
11327
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11328 {
11329 new_return(65);
11330 }
11331
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11332 {
11333 new_return(66);
11334 }
11335
11336
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11337 {
11338
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11339 {
11340 new_return(67);
11341 }
11342 92160 }
11343
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11344 {
11345 new_return(68);
11346 }
11347 //misc 16->31
11348
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11349 {
11350 new_return(69);
11351 }
11352
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11353 {
11354 new_return(70);
11355 }
11356
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11357 {
11358 new_return(71);
11359 }
11360
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11361 {
11362 new_return(72);
11363 }
11364
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11365 {
11366 new_return(73);
11367 }
11368
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11369 {
11370 new_return(74);
11371 }
11372
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11373 {
11374 new_return(75);
11375 }
11376
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11377 {
11378 new_return(76);
11379 }
11380
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11381 {
11382 new_return(77);
11383 }
11384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11385 {
11386 new_return(78);
11387 }
11388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11389 {
11390 new_return(79);
11391 }
11392
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11393 {
11394 new_return(80);
11395 }
11396
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11397 {
11398 new_return(81);
11399 }
11400
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11401 {
11402 new_return(82);
11403 }
11404
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11405 {
11406 new_return(83);
11407 }
11408
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11409 {
11410 new_return(84);
11411 }
11412
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11413 {
11414 new_return(85);
11415 }
11416
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11417 {
11418
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11419 {
11420 new_return(86);
11421 }
11422 294912 }
11423
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11424 {
11425
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11426 {
11427 new_return(87);
11428 }
11429 294912 }
11430
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11431 {
11432 new_return(88);
11433 }
11434
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11435 {
11436
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11437 {
11438 new_return(89);
11439 }
11440 73728 }
11441
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11442 {
11443
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11444 {
11445 new_return(90);
11446 }
11447 18432 }
11448
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11449 {
11450 new_return(91);
11451 }
11452 //somehow forgot these in the older builds -Z
11453
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11454 {
11455 new_return(92);
11456 }
11457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11458 {
11459 new_return(93);
11460 }
11461
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11462 {
11463 new_return(94);
11464 }
11465
11466 //Enemy Editor InitD[] labels
11467
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11468 {
11469
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11470 {
11471
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11472 {
11473 new_return(95);
11474 }
11475 4792320 }
11476 73728 }
11477
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11478 new_return(99);
11479
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11480 new_return(100);
11481
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11482 new_return(101);
11483
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11484 new_return(102);
11485
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11486 new_return(103);
11487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11488 return ret;
11489 9216 }
11490
11491
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11492 {
11493 9 section_size=writesize;
11494 9 }
11495 18 }
11496
11497
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11498 {
11499 char ebuf[80];
11500 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11501 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11502 }
11503
11504 9 new_return(0);
11505 9 }
11506
11507 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11508 {
11509 //these are here to bypass compiler warnings about unused arguments
11510 9 Header=Header;
11511
11512 9 dword section_id=ID_HEROSPRITES;
11513 9 dword section_version=V_HEROSPRITES;
11514 9 dword section_size=0;
11515
11516 //section id
11517
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11518 {
11519 new_return(1);
11520 }
11521
11522 //section version info
11523
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11524 {
11525 new_return(2);
11526 }
11527
11528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11529 {
11530 new_return(3);
11531 }
11532
11533
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11534 {
11535 18 fake_pack_writing=(writecycle==0);
11536
11537 //section size
11538
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11539 {
11540 new_return(4);
11541 }
11542
11543 18 writesize=0;
11544
11545 //finally... section data
11546
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11547 {
11548
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11549 {
11550 new_return(5);
11551 }
11552
11553
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11554 {
11555 new_return(5);
11556 }
11557
11558
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11559 {
11560 new_return(5);
11561 }
11562 72 }
11563
11564
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11565 {
11566
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11567 {
11568 new_return(6);
11569 }
11570
11571
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11572 {
11573 new_return(6);
11574 }
11575
11576
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11577 {
11578 new_return(6);
11579 }
11580 72 }
11581
11582
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11583 {
11584
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11585 {
11586 new_return(7);
11587 }
11588
11589
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11590 {
11591 new_return(7);
11592 }
11593
11594
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11595 {
11596 new_return(7);
11597 }
11598 72 }
11599
11600
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11601 {
11602
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11603 {
11604 new_return(8);
11605 }
11606
11607
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11608 {
11609 new_return(8);
11610 }
11611
11612
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11613 {
11614 new_return(8);
11615 }
11616 72 }
11617
11618
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11619 {
11620
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11621 {
11622 new_return(8);
11623 }
11624
11625
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11626 {
11627 new_return(8);
11628 }
11629
11630
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11631 {
11632 new_return(8);
11633 }
11634 72 }
11635
11636
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11637 {
11638
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11639 {
11640 new_return(9);
11641 }
11642
11643
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11644 {
11645 new_return(9);
11646 }
11647
11648
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11649 {
11650 new_return(9);
11651 }
11652 72 }
11653
11654
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11655 {
11656
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11657 {
11658 new_return(10);
11659 }
11660
11661
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11662 {
11663 new_return(10);
11664 }
11665
11666
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11667 {
11668 new_return(10);
11669 }
11670 72 }
11671
11672
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11673 {
11674 new_return(11);
11675 }
11676
11677
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11678 {
11679 new_return(11);
11680 }
11681
11682
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11683 {
11684 new_return(11);
11685 }
11686
11687
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11688 {
11689
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11690 {
11691
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11692 {
11693 new_return(12);
11694 }
11695
11696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11697 {
11698 new_return(12);
11699 }
11700
11701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11702 {
11703 new_return(12);
11704 }
11705 108 }
11706 36 }
11707
11708
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11709 {
11710
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11711 {
11712 new_return(13);
11713 }
11714
11715
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11716 {
11717 new_return(13);
11718 }
11719
11720
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11721 {
11722 new_return(13);
11723 }
11724 72 }
11725
11726
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11727 {
11728
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11729 {
11730 new_return(13);
11731 }
11732
11733
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11734 {
11735 new_return(13);
11736 }
11737
11738
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11739 {
11740 new_return(13);
11741 }
11742 72 }
11743
11744
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11745 {
11746 new_return(14);
11747 }
11748
11749 //{ V_HEROSPRITES >= 7
11750
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11751 {
11752
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11753 new_return(15);
11754
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11755 new_return(15);
11756
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11757 new_return(15);
11758 72 }
11759
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11760 {
11761
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11762 new_return(15);
11763
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11764 new_return(15);
11765
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11766 new_return(15);
11767 72 }
11768
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11769 {
11770
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11771 new_return(15);
11772
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11773 new_return(15);
11774
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11775 new_return(15);
11776 72 }
11777
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11778 {
11779
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11780 new_return(15);
11781
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11782 new_return(15);
11783
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11784 new_return(15);
11785 72 }
11786
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11787 {
11788
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11789 new_return(15);
11790
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11791 new_return(15);
11792
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11793 new_return(15);
11794 72 }
11795
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11796 {
11797
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11798 new_return(15);
11799
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11800 new_return(15);
11801
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11802 new_return(15);
11803 72 }
11804
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11805 {
11806
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11807 new_return(15);
11808
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11809 new_return(15);
11810
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11811 new_return(15);
11812 72 }
11813
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11814 {
11815
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11816 new_return(15);
11817
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11818 new_return(15);
11819
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11820 new_return(15);
11821 72 }
11822
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11823 {
11824
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11825 new_return(15);
11826
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11827 new_return(15);
11828
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11829 new_return(15);
11830
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11831 new_return(15);
11832 72 }
11833
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11834 {
11835
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11836 new_return(15);
11837
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11838 new_return(15);
11839
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11840 new_return(15);
11841 72 }
11842
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11843 {
11844
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11845 new_return(15);
11846
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11847 new_return(15);
11848
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11849 new_return(15);
11850 72 }
11851
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11852 {
11853
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11854 new_return(15);
11855
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11856 new_return(15);
11857
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11858 new_return(15);
11859 72 }
11860
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11861 {
11862
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11863 new_return(15);
11864
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11865 new_return(15);
11866
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11867 new_return(15);
11868 72 }
11869
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11870 {
11871
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11872 new_return(15);
11873
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11874 new_return(15);
11875
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11876 new_return(15);
11877 72 }
11878
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11879 {
11880
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11881 new_return(15);
11882
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11883 new_return(15);
11884
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11885 new_return(15);
11886 72 }
11887
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11888 {
11889
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11890 new_return(15);
11891
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11892 new_return(15);
11893
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11894 new_return(15);
11895 72 }
11896
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11897 {
11898
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11899 new_return(15);
11900
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11901 new_return(15);
11902
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11903 new_return(15);
11904 72 }
11905
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11906 {
11907
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11908 new_return(15);
11909
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11910 new_return(15);
11911
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11912 new_return(15);
11913 72 }
11914
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11915 {
11916
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11917 new_return(15);
11918
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11919 new_return(15);
11920
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11921 new_return(15);
11922 72 }
11923
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11924 {
11925
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11926 new_return(15);
11927
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11928 new_return(15);
11929
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11930 new_return(15);
11931 72 }
11932
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11933 {
11934
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11935 new_return(15);
11936
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11937 new_return(15);
11938
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11939 new_return(15);
11940 72 }
11941
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11942 {
11943
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11944 new_return(15);
11945
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11946 new_return(15);
11947
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11948 new_return(15);
11949 72 }
11950
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11951 {
11952
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11953 new_return(15);
11954
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11955 new_return(15);
11956
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11957 new_return(15);
11958 72 }
11959
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11960 {
11961
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11962 new_return(15);
11963
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11964 new_return(15);
11965
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11966 new_return(15);
11967 54 }
11968
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11969 {
11970
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11971 new_return(16);
11972
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11973 new_return(16);
11974
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11975 new_return(16);
11976 72 }
11977
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11978 {
11979
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11980 new_return(17);
11981
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11982 new_return(17);
11983
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
11984 new_return(17);
11985 72 }
11986
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11987 {
11988
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
11989 new_return(17);
11990
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
11991 new_return(17);
11992
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
11993 new_return(17);
11994 72 }
11995
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11996 {
11997
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
11998 new_return(17);
11999
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12000 new_return(17);
12001
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12002 new_return(17);
12003 72 }
12004
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12005 {
12006
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12007 new_return(18);
12008
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12009 new_return(18);
12010
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12011 new_return(18);
12012 72 }
12013
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12014 {
12015
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12016 new_return(19);
12017 72 }
12018
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12019 {
12020
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12021 new_return(20);
12022
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12023 new_return(20);
12024
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12025 new_return(20);
12026 54 }
12027
12028
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12029 {
12030 new_return(21);
12031 }
12032
12033
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12034 {
12035 new_return(21);
12036 }
12037
12038
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12039 {
12040 new_return(21);
12041 }
12042
12043
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12044 {
12045
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12046 new_return(22);
12047
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12048 new_return(22);
12049
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12050 new_return(22);
12051 72 }
12052
12053
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12054 {
12055
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12056 {
12057 new_return(23);
12058 }
12059
12060
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12061 {
12062 new_return(23);
12063 }
12064
12065
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12066 {
12067 new_return(23);
12068 }
12069 72 }
12070
12071
12072
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12073 {
12074
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12075 new_return(15);
12076 2628 }
12077 //}
12078
12079
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12080 {
12081 9 section_size=writesize;
12082 9 }
12083 18 }
12084
12085 //More data will come here
12086
12087
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12088 {
12089 char ebuf[80];
12090 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12091 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12092 }
12093
12094 9 new_return(0);
12095 }
12096
12097 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12098 {
12099 9 dword section_id=ID_SUBSCREEN;
12100 9 dword section_version=V_SUBSCREEN;
12101 9 dword section_size=0;
12102
12103 //section id
12104
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12105 {
12106 new_return(1);
12107 }
12108
12109 //section version info
12110
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12111 {
12112 new_return(2);
12113 }
12114
12115
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12116 {
12117 new_return(3);
12118 }
12119
12120
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12121 {
12122 18 fake_pack_writing=(writecycle==0);
12123
12124 //section size
12125
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12126 {
12127 new_return(4);
12128 }
12129
12130 18 writesize=0;
12131
12132 18 byte sz = subscreens_active.size();
12133
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12134 new_return(5);
12135
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12136 {
12137 86 int32_t ret = subscreens_active[i].write(f);
12138 86 fake_pack_writing=(writecycle==0);
12139
12140
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12141 new_return(ret);
12142 86 }
12143
12144 18 sz = subscreens_passive.size();
12145
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12146 new_return(5);
12147
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12148 {
12149 64 int32_t ret = subscreens_passive[i].write(f);
12150 64 fake_pack_writing=(writecycle==0);
12151
12152
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12153 new_return(ret);
12154 64 }
12155
12156 18 sz = subscreens_overlay.size();
12157
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12158 new_return(5);
12159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12160 {
12161 int32_t ret = subscreens_overlay[i].write(f);
12162 fake_pack_writing=(writecycle==0);
12163
12164 if(ret!=0)
12165 new_return(ret);
12166 }
12167
12168
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12169 {
12170 9 section_size=writesize;
12171 9 }
12172 18 }
12173
12174
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12175 {
12176 char ebuf[80];
12177 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12178 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12179 }
12180
12181 9 new_return(0);
12182 9 }
12183
12184 extern script_data *ffscripts[NUMSCRIPTFFC];
12185 extern script_data *itemscripts[NUMSCRIPTITEM];
12186 extern script_data *guyscripts[NUMSCRIPTGUYS];
12187 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12188 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12189 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12190 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12191 extern script_data *playerscripts[NUMSCRIPTHERO];
12192 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12193 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12194 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12195 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12196 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12197
12198 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12199 {
12200
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12201 3 return writeffscript_old(f, Header);
12202
12203 6 dword section_id = ID_FFSCRIPT;
12204 6 dword section_version = V_FFSCRIPT;
12205 6 dword section_size = 0;
12206 6 dword zasmmeta_version = METADATA_V;
12207 6 byte numscripts = 0;
12208 6 numscripts = numscripts; //to avoid unused variables warnings
12209
12210 //section id
12211
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12212 {
12213 new_return(1);
12214 }
12215
12216 //section version info
12217
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12218 {
12219 new_return(2);
12220 }
12221
12222
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12223 {
12224 new_return(3);
12225 }
12226
12227
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12228 {
12229 new_return(4);
12230 }
12231
12232
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12233 {
12234 12 fake_pack_writing=(writecycle==0);
12235
12236 //section size
12237
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12238 {
12239 new_return(5);
12240 }
12241
12242 12 writesize=0;
12243
12244 12 write_quest_zasm(f);
12245
12246
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12247 {
12248 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12249
12250
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12251 {
12252 new_return(ret);
12253 }
12254 6144 }
12255
12256
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12257 {
12258 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12259
12260
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12261 {
12262 new_return(ret);
12263 }
12264 3072 }
12265
12266
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12267 {
12268 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12269
12270
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12271 {
12272 new_return(ret);
12273 }
12274 3072 }
12275
12276
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12277
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12278 {
12279 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12280
12281
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12282 {
12283 new_return(ret);
12284 }
12285 3072 }
12286
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12287
12288
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12289 {
12290 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12291
12292
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12293 {
12294 new_return(ret);
12295 }
12296 3072 }
12297
12298
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12299 {
12300 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12301
12302
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12303 {
12304 new_return(ret);
12305 }
12306 96 }
12307
12308
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12309 {
12310 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12311
12312
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12313 {
12314 new_return(ret);
12315 }
12316 60 }
12317
12318
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12319 {
12320 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12321
12322
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12323 {
12324 new_return(ret);
12325 }
12326 3072 }
12327
12328
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12329 {
12330 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12331
12332
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12333 {
12334 new_return(ret);
12335 }
12336 3072 }
12337
12338
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12339 {
12340 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12341
12342
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12343 {
12344 new_return(ret);
12345 }
12346 3072 }
12347
12348
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12349 {
12350 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12351
12352
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12353 {
12354 new_return(ret);
12355 }
12356 3072 }
12357
12358
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12359 {
12360 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12361
12362
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12363 {
12364 new_return(ret);
12365 }
12366 6144 }
12367
12368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12369 {
12370 new_return(2000);
12371 }
12372
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12373 {
12374 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12375
12376
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12377 {
12378 new_return(ret);
12379 }
12380 6144 }
12381
12382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12383 {
12384 new_return(2001);
12385 }
12386
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12387 {
12388 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12389
12390
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12391 {
12392 new_return(ret);
12393 }
12394 3072 }
12395
12396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12397 {
12398 new_return(2001);
12399 }
12400
12401
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12402 {
12403 new_return(2002);
12404 }
12405
12406 12 word numffcbindings=0;
12407
12408
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12409 {
12410
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12411 {
12412 158 numffcbindings++;
12413 158 }
12414 6132 }
12415
12416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12417 {
12418 new_return(2003);
12419 }
12420
12421
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12422 {
12423
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12424 {
12425
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12426 {
12427 new_return(2004);
12428 }
12429
12430
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12431 {
12432 new_return(2005);
12433 }
12434
12435
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12436 {
12437 new_return(2006);
12438 }
12439 158 }
12440 6132 }
12441
12442 12 word numglobalbindings=0;
12443
12444
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12445 {
12446
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12447 {
12448 22 numglobalbindings++;
12449 22 }
12450 96 }
12451
12452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12453 {
12454 new_return(2007);
12455 }
12456
12457
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12458 {
12459
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12460 {
12461
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12462 {
12463 new_return(2008);
12464 }
12465
12466
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12467 {
12468 new_return(2009);
12469 }
12470
12471
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12472 {
12473 new_return(2010);
12474 }
12475 22 }
12476 96 }
12477
12478 12 word numitembindings=0;
12479
12480
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12481 {
12482
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12483 {
12484 26 numitembindings++;
12485 26 }
12486 3060 }
12487
12488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12489 {
12490 new_return(2011);
12491 }
12492
12493
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12494 {
12495
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12496 {
12497
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12498 {
12499 new_return(2012);
12500 }
12501
12502
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12503 {
12504 new_return(2013);
12505 }
12506
12507
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12508 {
12509 new_return(2014);
12510 }
12511 26 }
12512 3060 }
12513
12514 //new script types
12515 //npc scripts
12516 12 word numnpcbindings=0;
12517
12518
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12519 {
12520
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12521 {
12522 numnpcbindings++;
12523 }
12524 3060 }
12525
12526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12527 {
12528 new_return(2015);
12529 }
12530
12531
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12532 {
12533
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12534 {
12535 if(!p_iputw(it->first,f))
12536 {
12537 new_return(2016);
12538 }
12539
12540 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12541 {
12542 new_return(2017);
12543 }
12544
12545 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12546 {
12547 new_return(2018);
12548 }
12549 }
12550 3060 }
12551
12552 //lweapon
12553
12554 12 word numlwpnbindings=0;
12555
12556
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12557 {
12558
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12559 {
12560 2 numlwpnbindings++;
12561 2 }
12562 3060 }
12563
12564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12565 {
12566 new_return(2019);
12567 }
12568
12569
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12570 {
12571
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12572 {
12573
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12574 {
12575 new_return(2020);
12576 }
12577
12578
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12579 {
12580 new_return(2021);
12581 }
12582
12583
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12584 {
12585 new_return(2022);
12586 }
12587 2 }
12588 3060 }
12589
12590 //////
12591
12592 //eweapon
12593
12594
12595 12 word numewpnbindings=0;
12596
12597
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12598 {
12599
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12600 {
12601 numewpnbindings++;
12602 }
12603 3060 }
12604
12605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12606 {
12607 new_return(2023);
12608 }
12609
12610
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12611 {
12612
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12613 {
12614 if(!p_iputw(it->first,f))
12615 {
12616 new_return(2024);
12617 }
12618
12619 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12620 {
12621 new_return(2025);
12622 }
12623
12624 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12625 {
12626 new_return(2026);
12627 }
12628 }
12629 3060 }
12630
12631 //player scripts
12632 12 word numherobindings=0;
12633
12634
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12635 {
12636
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12637 {
12638 numherobindings++;
12639 }
12640 48 }
12641
12642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12643 {
12644 new_return(2027);
12645 }
12646
12647
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12648 {
12649
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12650 {
12651 if(!p_iputw(it->first,f))
12652 {
12653 new_return(2028);
12654 }
12655
12656 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12657 {
12658 new_return(2029);
12659 }
12660
12661 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12662 {
12663 new_return(2030);
12664 }
12665 }
12666 48 }
12667
12668 //dmap scripts
12669 12 word numdmapbindings=0;
12670
12671
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12672 {
12673
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12674 {
12675 10 numdmapbindings++;
12676 10 }
12677 3060 }
12678
12679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12680 {
12681 new_return(2031);
12682 }
12683
12684
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12685 {
12686
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12687 {
12688
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12689 {
12690 new_return(2032);
12691 }
12692
12693
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12694 {
12695 new_return(2033);
12696 }
12697
12698
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12699 {
12700 new_return(2034);
12701 }
12702 10 }
12703 3060 }
12704
12705 //screen scripts
12706 12 word numscreenbindings=0;
12707
12708
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12709 {
12710
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12711 {
12712 4 numscreenbindings++;
12713 4 }
12714 3060 }
12715
12716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12717 {
12718 new_return(2035);
12719 }
12720
12721
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12722 {
12723
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12724 {
12725
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12726 {
12727 new_return(2036);
12728 }
12729
12730
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12731 {
12732 new_return(2037);
12733 }
12734
12735
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12736 {
12737 new_return(2038);
12738 }
12739 4 }
12740 3060 }
12741 //item sprite scripts
12742 12 word numitemspritebindings=0;
12743
12744
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12745 {
12746
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12747 {
12748 numitemspritebindings++;
12749 }
12750 3060 }
12751
12752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12753 {
12754 new_return(2039);
12755 }
12756
12757
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12758 {
12759
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12760 {
12761 if(!p_iputw(it->first,f))
12762 {
12763 new_return(2040);
12764 }
12765
12766 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12767 {
12768 new_return(2041);
12769 }
12770
12771 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12772 {
12773 new_return(2042);
12774 }
12775 }
12776 3060 }
12777
12778 //combo scripts
12779 12 word numcombobindings=0;
12780
12781
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12782 {
12783
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12784 {
12785 numcombobindings++;
12786 }
12787 6132 }
12788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12789 {
12790 new_return(2043);
12791 }
12792
12793
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12794 {
12795
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12796 {
12797 if(!p_iputw(it->first,f))
12798 {
12799 new_return(2044);
12800 }
12801
12802 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12803 {
12804 new_return(2045);
12805 }
12806
12807 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12808 {
12809 new_return(2046);
12810 }
12811 }
12812 6132 }
12813 //subscreen scripts
12814 12 word numgenericbindings=0;
12815
12816
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12817 {
12818
2/2
✓ Branch 0 taken 6092 times.
✓ Branch 1 taken 40 times.
6132 if(it->second.scriptname != "")
12819 {
12820 40 numgenericbindings++;
12821 40 }
12822 6132 }
12823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12824 {
12825 new_return(2043);
12826 }
12827
12828
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12829 {
12830
2/2
✓ Branch 0 taken 6092 times.
✓ Branch 1 taken 40 times.
6132 if(it->second.scriptname != "")
12831 {
12832
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_iputw(it->first,f))
12833 {
12834 new_return(2044);
12835 }
12836
12837
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12838 {
12839 new_return(2045);
12840 }
12841
12842
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12843 {
12844 new_return(2046);
12845 }
12846 40 }
12847 6132 }
12848
12849 //generic scripts
12850 12 word numsubscreenbindings=0;
12851
12852
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12853 {
12854
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12855 {
12856 numsubscreenbindings++;
12857 }
12858 3060 }
12859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12860 {
12861 new_return(2047);
12862 }
12863
12864
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12865 {
12866
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12867 {
12868 if(!p_iputw(it->first,f))
12869 {
12870 new_return(2048);
12871 }
12872
12873 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12874 {
12875 new_return(2049);
12876 }
12877
12878 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12879 {
12880 new_return(2050);
12881 }
12882 }
12883 3060 }
12884
12885
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12886 {
12887 6 section_size=writesize;
12888 6 }
12889 12 }
12890
12891
12892
12893
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12894 {
12895 char ebuf[80];
12896 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12897 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12898 }
12899
12900 6 new_return(0);
12901 //return 0; //this is just here to stomp the compiler from whining.
12902 //the irony is that it causes an "unreachable code" warning.
12903 9 }
12904
12905 12 int32_t write_quest_zasm(PACKFILE *f)
12906 {
12907 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12908
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12909 {
12910 if(!p_iputl(0,f))
12911 new_return(1);
12912
12913 return 0;
12914 }
12915
12916 12 auto& zasm = zasm_scripts[0]->zasm;
12917 12 size_t num_commands = zasm.size();
12918
12919
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12920 new_return(1);
12921
12922
2/2
✓ Branch 0 taken 345632 times.
✓ Branch 1 taken 12 times.
345644 for(int32_t j=0; j<num_commands; j++)
12923 {
12924 345632 auto& zas = zasm[j];
12925
12926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 345632 times.
345632 if(zas.command==0xFFFF)
12927 continue;
12928 else
12929 {
12930
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputw(zas.command,f))
12931 new_return(2);
12932
12933
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg1,f))
12934 new_return(3);
12935
12936
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg2,f))
12937 new_return(4);
12938
12939
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg3,f))
12940 new_return(5);
12941
12942 345632 uint32_t sz = 0;
12943
2/2
✓ Branch 0 taken 344678 times.
✓ Branch 1 taken 954 times.
345632 if(zas.strptr)
12944 954 sz = zas.strptr->size();
12945
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(sz,f))
12946 new_return(6);
12947
2/2
✓ Branch 0 taken 344690 times.
✓ Branch 1 taken 942 times.
345632 if(sz)
12948 {
12949 942 auto& str = *zas.strptr;
12950
2/2
✓ Branch 0 taken 19592 times.
✓ Branch 1 taken 942 times.
20534 for(size_t q = 0; q < sz; ++q)
12951 {
12952
1/2
✓ Branch 0 taken 19592 times.
✗ Branch 1 not taken.
19592 if(!p_putc(str[q],f))
12953 new_return(7);
12954 19592 }
12955 942 }
12956 345632 sz = 0;
12957
2/2
✓ Branch 0 taken 345432 times.
✓ Branch 1 taken 200 times.
345632 if(zas.vecptr)
12958 200 sz = zas.vecptr->size();
12959
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(sz,f))
12960 new_return(8);
12961
2/2
✓ Branch 0 taken 345432 times.
✓ Branch 1 taken 200 times.
345632 if(sz) //vector found
12962 {
12963 200 auto& vec = *zas.vecptr;
12964
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 200 times.
1000 for(size_t q = 0; q < sz; ++q)
12965 {
12966
1/2
✓ Branch 0 taken 800 times.
✗ Branch 1 not taken.
800 if(!p_iputl(vec[q],f))
12967 new_return(9);
12968 800 }
12969 200 }
12970 }
12971 345632 }
12972 12 return 0;
12973 12 }
12974
12975 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
12976 {
12977
2/2
✓ Branch 0 taken 45988 times.
✓ Branch 1 taken 248 times.
46236 if (!script->valid())
12978 {
12979
1/2
✓ Branch 0 taken 45988 times.
✗ Branch 1 not taken.
45988 if (!p_putc(0, f))
12980 new_return(-1);
12981 45988 return 0;
12982 }
12983
12984
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if (!p_putc(1, f))
12985 new_return(-1);
12986
12987 248 zasm_meta const& tmeta = script->meta;
12988
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.zasm_v,f))
12989 new_return(1);
12990
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.meta_v,f))
12991 new_return(2);
12992
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.ffscript_v,f))
12993 new_return(3);
12994
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putc((int)tmeta.script_type,f))
12995 new_return(4);
12996
12997
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(int32_t q = 0; q < 8; ++q)
12998 {
12999
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.run_idens[q],f))
13000 new_return(5);
13001 1984 }
13002
13003
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(int32_t q = 0; q < 8; ++q)
13004
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putc(tmeta.run_types[q],f))
13005 new_return(6);
13006
13007
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putc(tmeta.flags,f))
13008 new_return(7);
13009
13010
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v1,f))
13011 new_return(8);
13012
13013
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v2,f))
13014 new_return(9);
13015
13016
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v3,f))
13017 new_return(10);
13018
13019
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v4,f))
13020 new_return(11);
13021
13022
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putcstr(tmeta.script_name,f))
13023 new_return(12);
13024
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putcstr(tmeta.author,f))
13025 new_return(13);
13026
2/2
✓ Branch 0 taken 2480 times.
✓ Branch 1 taken 248 times.
2728 for(auto q = 0; q < 10; ++q)
13027 {
13028
1/2
✓ Branch 0 taken 2480 times.
✗ Branch 1 not taken.
2480 if(!p_putcstr(tmeta.attributes[q],f))
13029 new_return(14);
13030
1/2
✓ Branch 0 taken 2480 times.
✗ Branch 1 not taken.
2480 if(!p_putwstr(tmeta.attributes_help[q],f))
13031 new_return(15);
13032 2480 }
13033
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13034 {
13035
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.attribytes[q],f))
13036 new_return(16);
13037
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.attribytes_help[q],f))
13038 new_return(17);
13039 1984 }
13040
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13041 {
13042
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.attrishorts[q],f))
13043 new_return(18);
13044
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13045 new_return(19);
13046 1984 }
13047
2/2
✓ Branch 0 taken 3968 times.
✓ Branch 1 taken 248 times.
4216 for(auto q = 0; q < 16; ++q)
13048 {
13049
1/2
✓ Branch 0 taken 3968 times.
✗ Branch 1 not taken.
3968 if(!p_putcstr(tmeta.usrflags[q],f))
13050 new_return(20);
13051
1/2
✓ Branch 0 taken 3968 times.
✗ Branch 1 not taken.
3968 if(!p_putwstr(tmeta.usrflags_help[q],f))
13052 new_return(21);
13053 3968 }
13054
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13055 {
13056
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.initd[q],f))
13057 new_return(22);
13058
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.initd_help[q],f))
13059 new_return(23);
13060 1984 }
13061
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13062 {
13063
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putc(tmeta.initd_type[q],f))
13064 new_return(24);
13065 1984 }
13066
13067
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputl(script->pc, f))
13068 new_return(25);
13069
13070
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 248 times.
248 if(!p_iputl(script->end_pc, f))
13071 new_return(26);
13072
13073 248 return 0;
13074 46236 }
13075
13076
13077 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13078 {
13079 3 dword section_id = ID_FFSCRIPT;
13080 3 dword section_version = 26;
13081 3 dword section_cversion = 1;
13082 3 dword section_size = 0;
13083 3 dword zasmmeta_version = 5;
13084 3 byte numscripts = 0;
13085 3 numscripts = numscripts; //to avoid unused variables warnings
13086
13087 //section id
13088
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13089 {
13090 new_return(1);
13091 }
13092
13093 //section version info
13094
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13095 {
13096 new_return(2);
13097 }
13098
13099
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13100 {
13101 new_return(3);
13102 }
13103
13104
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13105 {
13106 new_return(4);
13107 }
13108
13109
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13110 {
13111 6 fake_pack_writing=(writecycle==0);
13112
13113 //section size
13114
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13115 {
13116 new_return(5);
13117 }
13118
13119 6 writesize=0;
13120
13121
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13122 {
13123 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13124 3072 fake_pack_writing=(writecycle==0);
13125
13126
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13127 {
13128 new_return(ret);
13129 }
13130 3072 }
13131
13132
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13133 {
13134 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13135 1536 fake_pack_writing=(writecycle==0);
13136
13137
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13138 {
13139 new_return(ret);
13140 }
13141 1536 }
13142
13143
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13144 {
13145 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13146 1536 fake_pack_writing=(writecycle==0);
13147
13148
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13149 {
13150 new_return(ret);
13151 }
13152 1536 }
13153
13154
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13155
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13156 {
13157 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13158 1536 fake_pack_writing=(writecycle==0);
13159
13160
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13161 {
13162 new_return(ret);
13163 }
13164 1536 }
13165
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13166
13167
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13168 {
13169 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13170 1536 fake_pack_writing=(writecycle==0);
13171
13172
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13173 {
13174 new_return(ret);
13175 }
13176 1536 }
13177
13178
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13179 {
13180 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13181 48 fake_pack_writing=(writecycle==0);
13182
13183
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13184 {
13185 new_return(ret);
13186 }
13187 48 }
13188
13189
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13190 {
13191 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13192 30 fake_pack_writing=(writecycle==0);
13193
13194
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13195 {
13196 new_return(ret);
13197 }
13198 30 }
13199
13200
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13201 {
13202 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13203 1536 fake_pack_writing=(writecycle==0);
13204
13205
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13206 {
13207 new_return(ret);
13208 }
13209 1536 }
13210
13211
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13212 {
13213 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13214 1536 fake_pack_writing=(writecycle==0);
13215
13216
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13217 {
13218 new_return(ret);
13219 }
13220 1536 }
13221
13222
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13223 {
13224 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13225 1536 fake_pack_writing=(writecycle==0);
13226
13227
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13228 {
13229 new_return(ret);
13230 }
13231 1536 }
13232
13233
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13234 {
13235 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13236 1536 fake_pack_writing=(writecycle==0);
13237
13238
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13239 {
13240 new_return(ret);
13241 }
13242 1536 }
13243
13244
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13245 {
13246 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13247 3072 fake_pack_writing=(writecycle==0);
13248
13249
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13250 {
13251 new_return(ret);
13252 }
13253 3072 }
13254
13255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13256 {
13257 new_return(2000);
13258 }
13259
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13260 {
13261 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13262 3072 fake_pack_writing=(writecycle==0);
13263
13264
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13265 {
13266 new_return(ret);
13267 }
13268 3072 }
13269
13270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13271 {
13272 new_return(2001);
13273 }
13274
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13275 {
13276 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13277 1536 fake_pack_writing=(writecycle==0);
13278
13279
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13280 {
13281 new_return(ret);
13282 }
13283 1536 }
13284
13285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13286 {
13287 new_return(2001);
13288 }
13289
13290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13291 {
13292 new_return(2002);
13293 }
13294
13295 6 word numffcbindings=0;
13296
13297
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13298 {
13299
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13300 {
13301 206 numffcbindings++;
13302 206 }
13303 3066 }
13304
13305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13306 {
13307 new_return(2003);
13308 }
13309
13310
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13311 {
13312
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13313 {
13314
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13315 {
13316 new_return(2004);
13317 }
13318
13319
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13320 {
13321 new_return(2005);
13322 }
13323
13324
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13325 {
13326 new_return(2006);
13327 }
13328 206 }
13329 3066 }
13330
13331 6 word numglobalbindings=0;
13332
13333
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13334 {
13335
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13336 {
13337 18 numglobalbindings++;
13338 18 }
13339 48 }
13340
13341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13342 {
13343 new_return(2007);
13344 }
13345
13346
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13347 {
13348
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13349 {
13350
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13351 {
13352 new_return(2008);
13353 }
13354
13355
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13356 {
13357 new_return(2009);
13358 }
13359
13360
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13361 {
13362 new_return(2010);
13363 }
13364 18 }
13365 48 }
13366
13367 6 word numitembindings=0;
13368
13369
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13370 {
13371
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13372 {
13373 18 numitembindings++;
13374 18 }
13375 1530 }
13376
13377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13378 {
13379 new_return(2011);
13380 }
13381
13382
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13383 {
13384
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13385 {
13386
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13387 {
13388 new_return(2012);
13389 }
13390
13391
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13392 {
13393 new_return(2013);
13394 }
13395
13396
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13397 {
13398 new_return(2014);
13399 }
13400 18 }
13401 1530 }
13402
13403 //new script types
13404 //npc scripts
13405 6 word numnpcbindings=0;
13406
13407
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13408 {
13409
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13410 {
13411 numnpcbindings++;
13412 }
13413 1530 }
13414
13415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13416 {
13417 new_return(2015);
13418 }
13419
13420
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13421 {
13422
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13423 {
13424 if(!p_iputw(it->first,f))
13425 {
13426 new_return(2016);
13427 }
13428
13429 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13430 {
13431 new_return(2017);
13432 }
13433
13434 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13435 {
13436 new_return(2018);
13437 }
13438 }
13439 1530 }
13440
13441 //lweapon
13442
13443 6 word numlwpnbindings=0;
13444
13445
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13446 {
13447
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13448 {
13449 numlwpnbindings++;
13450 }
13451 1530 }
13452
13453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13454 {
13455 new_return(2019);
13456 }
13457
13458
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13459 {
13460
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13461 {
13462 if(!p_iputw(it->first,f))
13463 {
13464 new_return(2020);
13465 }
13466
13467 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13468 {
13469 new_return(2021);
13470 }
13471
13472 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13473 {
13474 new_return(2022);
13475 }
13476 }
13477 1530 }
13478
13479 //////
13480
13481 //eweapon
13482
13483
13484 6 word numewpnbindings=0;
13485
13486
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13487 {
13488
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13489 {
13490 numewpnbindings++;
13491 }
13492 1530 }
13493
13494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13495 {
13496 new_return(2023);
13497 }
13498
13499
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13500 {
13501
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13502 {
13503 if(!p_iputw(it->first,f))
13504 {
13505 new_return(2024);
13506 }
13507
13508 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13509 {
13510 new_return(2025);
13511 }
13512
13513 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13514 {
13515 new_return(2026);
13516 }
13517 }
13518 1530 }
13519
13520 //player scripts
13521 6 word numherobindings=0;
13522
13523
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13524 {
13525
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13526 {
13527 2 numherobindings++;
13528 2 }
13529 24 }
13530
13531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13532 {
13533 new_return(2027);
13534 }
13535
13536
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13537 {
13538
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13539 {
13540
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13541 {
13542 new_return(2028);
13543 }
13544
13545
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13546 {
13547 new_return(2029);
13548 }
13549
13550
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13551 {
13552 new_return(2030);
13553 }
13554 2 }
13555 24 }
13556
13557 //dmap scripts
13558 6 word numdmapbindings=0;
13559
13560
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13561 {
13562
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13563 {
13564 numdmapbindings++;
13565 }
13566 1530 }
13567
13568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13569 {
13570 new_return(2031);
13571 }
13572
13573
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13574 {
13575
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13576 {
13577 if(!p_iputw(it->first,f))
13578 {
13579 new_return(2032);
13580 }
13581
13582 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13583 {
13584 new_return(2033);
13585 }
13586
13587 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13588 {
13589 new_return(2034);
13590 }
13591 }
13592 1530 }
13593
13594 //screen scripts
13595 6 word numscreenbindings=0;
13596
13597
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13598 {
13599
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13600 {
13601 14 numscreenbindings++;
13602 14 }
13603 1530 }
13604
13605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13606 {
13607 new_return(2035);
13608 }
13609
13610
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13611 {
13612
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13613 {
13614
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13615 {
13616 new_return(2036);
13617 }
13618
13619
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13620 {
13621 new_return(2037);
13622 }
13623
13624
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13625 {
13626 new_return(2038);
13627 }
13628 14 }
13629 1530 }
13630 //item sprite scripts
13631 6 word numitemspritebindings=0;
13632
13633
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13634 {
13635
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13636 {
13637 numitemspritebindings++;
13638 }
13639 1530 }
13640
13641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13642 {
13643 new_return(2039);
13644 }
13645
13646
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13647 {
13648
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13649 {
13650 if(!p_iputw(it->first,f))
13651 {
13652 new_return(2040);
13653 }
13654
13655 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13656 {
13657 new_return(2041);
13658 }
13659
13660 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13661 {
13662 new_return(2042);
13663 }
13664 }
13665 1530 }
13666
13667 //combo scripts
13668 6 word numcombobindings=0;
13669
13670
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13671 {
13672
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13673 {
13674 numcombobindings++;
13675 }
13676 3066 }
13677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13678 {
13679 new_return(2043);
13680 }
13681
13682
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13683 {
13684
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13685 {
13686 if(!p_iputw(it->first,f))
13687 {
13688 new_return(2044);
13689 }
13690
13691 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13692 {
13693 new_return(2045);
13694 }
13695
13696 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13697 {
13698 new_return(2046);
13699 }
13700 }
13701 3066 }
13702 //subscreen scripts
13703 6 word numgenericbindings=0;
13704
13705
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13706 {
13707
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13708 {
13709 numgenericbindings++;
13710 }
13711 3066 }
13712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13713 {
13714 new_return(2043);
13715 }
13716
13717
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13718 {
13719
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13720 {
13721 if(!p_iputw(it->first,f))
13722 {
13723 new_return(2044);
13724 }
13725
13726 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13727 {
13728 new_return(2045);
13729 }
13730
13731 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13732 {
13733 new_return(2046);
13734 }
13735 }
13736 3066 }
13737
13738 //generic scripts
13739 6 word numsubscreenbindings=0;
13740
13741
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13742 {
13743
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13744 {
13745 numsubscreenbindings++;
13746 }
13747 1530 }
13748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13749 {
13750 new_return(2047);
13751 }
13752
13753
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13754 {
13755
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13756 {
13757 if(!p_iputw(it->first,f))
13758 {
13759 new_return(2048);
13760 }
13761
13762 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13763 {
13764 new_return(2049);
13765 }
13766
13767 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13768 {
13769 new_return(2050);
13770 }
13771 }
13772 1530 }
13773
13774
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13775 {
13776 3 section_size=writesize;
13777 3 }
13778 6 }
13779
13780
13781
13782
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13783 {
13784 char ebuf[80];
13785 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13786 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13787 }
13788
13789 3 new_return(0);
13790 //return 0; //this is just here to stomp the compiler from whining.
13791 //the irony is that it causes an "unreachable code" warning.
13792 3 }
13793
13794 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13795 {
13796 //these are here to bypass compiler warnings about unused arguments
13797 23118 Header=Header;
13798 23118 i=i;
13799
13800
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13801
13802
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13803 {
13804 new_return(6);
13805 }
13806
13807 //Metadata
13808 23118 zasm_meta const& tmeta = script->meta;
13809
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13810 {
13811 new_return(7);
13812 }
13813
13814
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13815 {
13816 new_return(8);
13817 }
13818
13819
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13820 {
13821 new_return(9);
13822 }
13823
13824
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13825 {
13826 new_return(10);
13827 }
13828
13829
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13830 {
13831
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13832 new_return(11);
13833 184944 }
13834
13835
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13836 {
13837
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13838 {
13839 new_return(12);
13840 }
13841 184944 }
13842
13843
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13844 {
13845 new_return(13);
13846 }
13847
13848
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13849 {
13850 new_return(14);
13851 }
13852
13853
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13854 {
13855 new_return(15);
13856 }
13857
13858
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13859 {
13860 new_return(16);
13861 }
13862
13863
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13864 {
13865 new_return(17);
13866 }
13867
13868
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13869 new_return(18);
13870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13871 new_return(19);
13872
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13873 {
13874
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13875 new_return(27);
13876
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13877 new_return(28);
13878 231180 }
13879
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13880 {
13881
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13882 new_return(29);
13883
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13884 new_return(30);
13885 184944 }
13886
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13887 {
13888
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13889 new_return(31);
13890
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13891 new_return(32);
13892 184944 }
13893
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13894 {
13895
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13896 new_return(33);
13897
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13898 new_return(34);
13899 369888 }
13900
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13901 {
13902
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13903 new_return(35);
13904
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13905 new_return(36);
13906 184944 }
13907
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13908 {
13909
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13910 new_return(37);
13911 184944 }
13912
13913
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13914 {
13915 2056888 auto& zas = script->zasm_script->zasm[j];
13916
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13917 {
13918 new_return(20);
13919 }
13920
13921
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13922 {
13923 11830 break;
13924 }
13925 else
13926 {
13927
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13928 {
13929 new_return(21);
13930 }
13931
13932
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13933 {
13934 new_return(22);
13935 }
13936
13937
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13938 {
13939 new_return(23);
13940 }
13941
13942 2045058 uint32_t sz = 0;
13943
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13944 2340 sz = zas.strptr->size();
13945
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13946 {
13947 new_return(23);
13948 }
13949
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13950 {
13951 2340 auto& str = *zas.strptr;
13952
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13953 {
13954
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13955 {
13956 new_return(24);
13957 }
13958 214720 }
13959 2340 }
13960 2045058 sz = 0;
13961
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13962 22 sz = zas.vecptr->size();
13963
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13964 {
13965 new_return(25);
13966 }
13967
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13968 {
13969 22 auto& vec = *zas.vecptr;
13970
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13971 {
13972
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13973 {
13974 new_return(26);
13975 }
13976 352 }
13977 22 }
13978 }
13979 2045058 }
13980
13981 23118 new_return(0);
13982 }
13983
13984 extern SAMPLE customsfxdata[WAV_COUNT];
13985 extern uint8_t customsfxflag[WAV_COUNT>>3];
13986
13987 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13988 {
13989 //these are here to bypass compiler warnings about unused arguments
13990 9 Header=Header;
13991
13992 9 dword section_id=ID_SFX;
13993 9 dword section_version=V_SFX;
13994 9 dword section_size=0;
13995
13996 //section id
13997
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
13998 {
13999 new_return(1);
14000 }
14001
14002 //section version info
14003
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14004 {
14005 new_return(2);
14006 }
14007
14008
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14009 {
14010 new_return(3);
14011 }
14012
14013
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14014 {
14015 18 fake_pack_writing=(writecycle==0);
14016
14017 //section size
14018
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14019 {
14020 new_return(4);
14021 }
14022
14023 18 writesize=0;
14024
14025
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14026 {
14027
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14028 {
14029 new_return(5);
14030 }
14031 576 }
14032
14033
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14034 {
14035
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14036 3330 continue;
14037
14038
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14039 {
14040 new_return(5);
14041 }
14042 1260 }
14043
14044
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14045 {
14046
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14047 3330 continue;
14048
14049
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14050 {
14051 new_return(5);
14052 }
14053
14054
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14055 {
14056 new_return(6);
14057 }
14058
14059
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14060 {
14061 new_return(7);
14062 }
14063
14064
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14065 {
14066 new_return(8);
14067 }
14068
14069
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14070 {
14071 new_return(9);
14072 }
14073
14074
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14075 {
14076 new_return(10);
14077 }
14078
14079
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14080 {
14081 new_return(11);
14082 }
14083
14084
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14085 {
14086 new_return(12);
14087 }
14088
14089 //de-endianfy the data
14090 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14091
14092
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14093 {
14094
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14095 {
14096 new_return(13);
14097 }
14098 28596352 }
14099 1260 }
14100
14101
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14102 {
14103 9 section_size=writesize;
14104 9 }
14105 18 }
14106
14107
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14108 {
14109 char ebuf[80];
14110 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14111 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14112 }
14113
14114 9 new_return(0);
14115 }
14116
14117 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14118 {
14119 9 dword section_id=ID_INITDATA;
14120 9 dword section_version=V_INITDATA;
14121 9 dword section_size = 0;
14122
14123 9 zinit.last_map=Map.getCurrMap();
14124 9 zinit.last_screen=Map.getCurrScr();
14125 9 zinit.normalize();
14126
14127 //section id
14128
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14129 {
14130 new_return(1);
14131 }
14132
14133 //section version info
14134
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14135 {
14136 new_return(2);
14137 }
14138
14139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14140 {
14141 new_return(3);
14142 }
14143
14144 //TODO
14145
14146
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14147 {
14148 18 fake_pack_writing=(writecycle==0);
14149
14150 //section size
14151
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14152 new_return(4);
14153
14154 18 writesize=0;
14155
14156
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14157
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14158 new_return(5);
14159
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14160 {
14161
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14162 new_return(6);
14163 9216 }
14164
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14165 new_return(10);
14166
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14167 new_return(11);
14168
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14169
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14170 new_return(12);
14171
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14172
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14173 new_return(13);
14174
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14175 new_return(14);
14176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14177 new_return(15);
14178
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14179 new_return(16);
14180
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14181 new_return(17);
14182
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14183 new_return(18);
14184
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14185 new_return(19);
14186
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14187 new_return(20);
14188
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14189 new_return(21);
14190
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14191 new_return(22);
14192
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14193 new_return(23);
14194
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14195 new_return(24);
14196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14197 new_return(25);
14198
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14199 new_return(26);
14200
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14201 new_return(27);
14202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14203 new_return(28);
14204
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14205 new_return(29);
14206
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14207 new_return(30);
14208
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14209 new_return(31);
14210
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14211 new_return(32);
14212
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14213 new_return(33);
14214
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14215 new_return(34);
14216
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14217 new_return(35);
14218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14219 new_return(36);
14220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14221 new_return(37);
14222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14223 new_return(38);
14224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14225 new_return(39);
14226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14227 new_return(40);
14228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14229 new_return(41);
14230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14231 new_return(42);
14232
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14233 new_return(43);
14234
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14235 new_return(44);
14236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14237 new_return(45);
14238
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14239 new_return(46);
14240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14241 new_return(47);
14242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14243 new_return(48);
14244
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14245 new_return(49);
14246
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14247 new_return(50);
14248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14249 new_return(51);
14250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14251 new_return(52);
14252
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14253 new_return(53);
14254
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14255 new_return(54);
14256
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14257 new_return(55);
14258
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14259 new_return(56);
14260
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14261 new_return(57);
14262
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14263 new_return(58);
14264
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14265 new_return(59);
14266
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14267 new_return(60);
14268
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14269 new_return(61);
14270
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14271 new_return(62);
14272
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14273 new_return(63);
14274
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14275 new_return(64);
14276
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14277 new_return(65);
14278
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14279 new_return(66);
14280
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14281 new_return(67);
14282
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14283 new_return(68);
14284
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14285 new_return(69);
14286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14287 new_return(70);
14288
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14289 new_return(71);
14290
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14291 new_return(72);
14292
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14293 new_return(73);
14294
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14295 new_return(74);
14296
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14297 new_return(75);
14298
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14299
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14300 new_return(76);
14301
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14302 new_return(77);
14303
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14304 new_return(78);
14305
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14306 new_return(79);
14307
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14308 new_return(80);
14309
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14310 new_return(81);
14311
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14312
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14313 new_return(82);
14314
14315
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14316 {
14317 9 section_size=writesize;
14318 9 }
14319 18 }
14320
14321
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14322 {
14323 char ebuf[80];
14324 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14325 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14326 }
14327
14328 9 new_return(0);
14329 }
14330
14331 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14332 {
14333 //these are here to bypass compiler warnings about unused arguments
14334 9 Header=Header;
14335
14336 9 dword section_id=ID_ITEMDROPSETS;
14337 9 dword section_version=V_ITEMDROPSETS;
14338 // dword section_size=0;
14339 9 dword section_size = 0;
14340 9 word num_item_drop_sets=count_item_drop_sets();
14341
14342 //section id
14343
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14344 {
14345 new_return(1);
14346 }
14347
14348 //section version info
14349
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14350 {
14351 new_return(2);
14352 }
14353
14354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14355 {
14356 new_return(3);
14357 }
14358
14359
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14360 {
14361 18 fake_pack_writing=(writecycle==0);
14362
14363 //section size
14364
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14365 {
14366 new_return(4);
14367 }
14368
14369 18 writesize=0;
14370
14371 //finally... section data
14372
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14373 {
14374 new_return(5);
14375 }
14376
14377
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14378 {
14379
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14380 {
14381 new_return(6);
14382 }
14383
14384
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14385 {
14386
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14387 {
14388 new_return(7);
14389 }
14390 2360 }
14391
14392
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14393 {
14394
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14395 {
14396 new_return(8);
14397 }
14398 2596 }
14399 236 }
14400
14401
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14402 {
14403 9 section_size=writesize;
14404 9 }
14405 18 }
14406
14407
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14408 {
14409 char ebuf[80];
14410 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14411 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14412 }
14413
14414 9 new_return(0);
14415 }
14416
14417 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14418 {
14419 9 dword section_id=ID_FAVORITES;
14420 9 dword section_version=V_FAVORITES;
14421 9 dword section_size = 0;
14422
14423 //section id
14424
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14425 {
14426 new_return(1);
14427 }
14428
14429 //section version info
14430
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14431 {
14432 new_return(2);
14433 }
14434
14435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14436 {
14437 new_return(3);
14438 }
14439
14440
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14441 {
14442 18 fake_pack_writing=(writecycle==0);
14443
14444 //section size
14445
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14446 new_return(4);
14447
14448 18 writesize=0;
14449
14450
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14451 new_return(16);
14452
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14453 new_return(17);
14454
14455 18 word favcmb_cnt = 0;
14456
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14457
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14458 {
14459 14 favcmb_cnt = q+1;
14460 14 break;
14461 }
14462
14463
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14464 new_return(5);
14465
14466
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14467 {
14468
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14469 new_return(6);
14470
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14471 new_return(7);
14472 460 }
14473
14474
14475 18 word max_combo_cols = MAX_COMBO_COLS;
14476
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14477 new_return(9);
14478
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14479 {
14480
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14481 new_return(10);
14482
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14483 new_return(11);
14484
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14485 new_return(12);
14486 72 }
14487 18 word max_mappages = MAX_MAPPAGE_BTNS;
14488
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14489 new_return(13);
14490
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14491 {
14492
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14493 new_return(14);
14494
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14495 new_return(15);
14496 162 }
14497
14498
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14499 {
14500 9 section_size=writesize;
14501 9 }
14502 18 }
14503
14504
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14505 {
14506 char ebuf[80];
14507 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14508 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14509 }
14510
14511 9 new_return(0);
14512 }
14513
14514 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14515 {
14516
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14517 9 reset_combo_animations();
14518 9 reset_combo_animations2();
14519 9 strcpy(header.id_str,QH_NEWIDSTR);
14520 9 header.zelda_version = ZELDA_VERSION;
14521 9 header.internal = INTERNAL_VERSION;
14522 9 header.data_flags[ZQ_TILES] = true;
14523 9 header.data_flags[ZQ_CHEATS2] = 1;
14524 9 header.build=VERSION_BUILD;
14525
14526
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14527 {
14528 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14529 2268 }
14530
14531 char zinfofilename[2048];
14532 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14533
14534 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14535 9 box_out("Saving Quest...");
14536 9 box_eol();
14537 9 box_eol();
14538
14539
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14540
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14541
14542
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14543 return 1;
14544
14545
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14546
14547
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14548 return 2;
14549
14550
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14551
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14552
14553
14554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14555 {
14556 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14557
14558 box_out("Writing ZInfo...");
14559 if(inf)
14560 {
14561 if(writezinfo(inf,ZI)!=0)
14562 return 2;
14563
14564 pack_fclose(inf);
14565 box_out("okay.");
14566 }
14567 else box_out(" ...file failure");
14568 box_eol();
14569 }
14570 else
14571 {
14572
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14573
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14574 return 2;
14575
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14576
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14577 }
14578
14579
14580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14581
14582
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14583 return 3;
14584
14585
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14586
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14587
14588
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14589
14590
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14591 return 4;
14592
14593
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14594
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14595
14596
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14597
14598
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14599 return 5;
14600
14601
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14602
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14603
14604
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14605
14606
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14607 return 6;
14608
14609
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14610
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14611
14612
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14613
14614
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14615 return 7;
14616
14617
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14618
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14619
14620
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14621
14622
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14623 return 8;
14624
14625
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14626
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14627
14628
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14629
14630
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14631 return 9;
14632
14633
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14634
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14635
14636
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14637
14638
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14639 return 10;
14640
14641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14642
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14643
14644
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14645
14646
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14647 return 11;
14648
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14650
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14651
14652
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14653
14654
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14655 return 12;
14656
14657
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14658
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14659
14660
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14661
14662
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14663 return 13;
14664
14665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14667
14668
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14669
14670
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14671 return 14;
14672
14673
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14674
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14675
14676
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14677
14678
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14679 return 15;
14680
14681
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14682
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14683
14684
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14685
14686
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14687 return 16;
14688
14689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14691
14692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14693
14694
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14695 return 17;
14696
14697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14698
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14699
14700
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14701
14702
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14703 return 18;
14704
14705
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14706
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14707
14708
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14709
14710
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14711 return 19;
14712
14713
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14714
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14715
14716
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14717
14718
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14719 return 20;
14720
14721
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14722
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14723
14724
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14725
14726
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14727 return 21;
14728
14729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14730
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14731
14732
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14733
14734
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14735 return 22;
14736
14737
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14738
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14739
14740
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14741
14742
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14743 return 23;
14744
14745
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14746
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14747
14748
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14749
14750
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14751 return 24;
14752
14753
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14754
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14755
14756
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14757
14758
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14759 return 25;
14760
14761
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14762
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14763
14764
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14765
14766
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14767 return 26;
14768
14769
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14770
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14771
14772
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14773
14774
14775
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14776 {
14777 char const* kfname = filename;
14778 char keyfilename[2048]={0};
14779 zprint2("Writing key files for '%s'\n", kfname);
14780
14781 char temp_pw[QSTPWD_LEN] = {0};
14782 uint ind = 0;
14783 for(char const* ext : {"key","zpwd","zcheat"})
14784 {
14785 replace_extension(keyfilename, kfname, ext, 2047);
14786 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14787 char msg[80] = {0};
14788 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14789 msg[78]=13;
14790 msg[79]=10;
14791 pfwrite(msg, 80, fp);
14792 p_iputw(header.zelda_version,fp);
14793 p_putc(header.build,fp);
14794 char const* pwd = header.password;
14795 if(ind == 2) //.zcheat, hashed pwd
14796 {
14797 char hashmap = 'Z';
14798 hashmap += 'Q';
14799 hashmap += 'U';
14800 hashmap += 'E';
14801 hashmap += 'S';
14802 hashmap += 'T';
14803 for ( int q = 0; q < QSTPWD_LEN; ++q )
14804 {
14805 temp_pw[q] = header.password[q];
14806 temp_pw[q] += hashmap;
14807 }
14808 pwd = temp_pw;
14809 }
14810 pfwrite(pwd, strlen(pwd), fp);
14811 pack_fclose(fp);
14812 ++ind;
14813 }
14814 }
14815
14816 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14817 9 std::error_code ec;
14818
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14820 {
14821 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14822 return ec.value();
14823 }
14824
14825
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14826
14827 #ifdef __EMSCRIPTEN__
14828 em_sync_fs();
14829 #endif
14830
14831 9 return 0;
14832 9 }
14833
14834 // #ifdef _WIN32
14835 // static std::time_t to_time_t(FILETIME const& ft) {
14836 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14837 // t -= 116444736000000000ull;
14838 // t /= 10000000u;
14839 // return static_cast<std::time_t>(t);
14840 // }
14841 // #else
14842 // #endif
14843 template<typename TP>
14844 6 static std::time_t to_time_t(TP tp) {
14845 using namespace std::chrono;
14846 6 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14847 6 return system_clock::to_time_t(sctp);
14848 }
14849
14850 6 std::string get_time_last_modified_string(std::string path)
14851 {
14852
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto write_time = fs::last_write_time(path);
14853 // TODO: C++20 but not supported yet.
14854 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14855 6 std::time_t tt = to_time_t(write_time);
14856 6 std::tm *gmt = std::gmtime(&tt);
14857 6 std::stringstream buffer;
14858
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 buffer << std::put_time(gmt, "%Y-%m-%d");
14859
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string formattedFileTime = buffer.str();
14860 6 return formattedFileTime;
14861
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 }
14862
14863 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14864 {
14865 // Always backup quest if it was last saved in a different version of the editor,
14866 // or if this a new file and is overwritting another qst file.
14867
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14868 {
14869 6 std::string backup_name;
14870
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string last_mod = get_time_last_modified_string(filename);
14871
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (strlen(header.zelda_version_string) > 0)
14872 {
14873
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14874 6 }
14875 else
14876 {
14877 backup_name = fmt::format("{}", last_mod);
14878 }
14879
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
6 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14880
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 fs::path backup_path = fs::path("backups") / backup_fname;
14881
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!fs::exists(backup_path))
14882 {
14883
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::create_directories(fs::path("backups"));
14884
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if (fs::copy_file(filename, backup_path))
14885 {
14886
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
6 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14887 6 }
14888 else
14889 {
14890 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14891 }
14892 6 }
14893 6 }
14894
14895 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14896 9 fake_pack_writing = false;
14897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14898 {
14899 box_out("-- Error saving quest file! --");
14900 box_end(true);
14901 }
14902 9 else box_end(false);
14903 9 return ret;
14904 }
14905
14906 9 int32_t save_quest(const char *filename, bool timed_save)
14907 {
14908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14909
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14910 char ext1[5];
14911 9 ext1[0]=0;
14912
14913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14914 {
14915 sprintf(ext1, "qt");
14916 }
14917 else
14918 {
14919 9 sprintf(ext1, "qb");
14920 }
14921
14922
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14923 {
14924 char backupname[2048];
14925 char backupname2[2048];
14926 char ext[12];
14927
14928 for(int32_t i=retention-1; i>0; --i)
14929 {
14930 sprintf(ext, "%s%d", ext1, i-1);
14931 replace_extension(backupname, filepath, ext, 2047);
14932
14933 if(exists(backupname))
14934 {
14935 sprintf(ext, "%s%d", ext1, i);
14936 replace_extension(backupname2, filepath, ext, 2047);
14937
14938 if(exists(backupname2))
14939 {
14940 remove(backupname2);
14941 }
14942
14943 rename(backupname, backupname2);
14944 }
14945 }
14946
14947 //don't do this if we're not saving to the same name -DD
14948 if(!timed_save && !strcmp(filepath, filename))
14949 {
14950 sprintf(ext, "%s%d", ext1, 0);
14951 replace_extension(backupname, filepath, ext, 2047);
14952 rename(filepath, backupname);
14953 }
14954 }
14955
14956 int32_t ret;
14957 9 ret = save_unencoded_quest(filename, compress, filename);
14958
14959 9 return ret;
14960 }
14961
14962 8 void center_zq_class_dialogs()
14963 {
14964 8 jwin_center_dialog(pwd_dlg);
14965 8 }
14966
14967 void zmap::prv_secrets(bool high16only)
14968 {
14969 mapscr *s = &prvscr;
14970 mapscr *t = prvlayers;
14971 int32_t ft=0;
14972
14973 for(int32_t i=0; i<176; i++)
14974 {
14975 if(!high16only)
14976 {
14977 for(int32_t j=-1; j<6; j++)
14978 {
14979 int32_t newflag = -1;
14980
14981 for(int32_t iter=0; iter<2; ++iter)
14982 {
14983 if(!t[j].valid)
14984 continue;
14985
14986 int32_t checkflag=combobuf[t[j].data[i]].flag;
14987
14988 if(iter==1)
14989 {
14990 checkflag=t[j].sflag[i];
14991 }
14992
14993 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
14994 if (ft != -1)
14995 {
14996 if(j==-1)
14997 {
14998 s->data[i] = s->secretcombo[ft];
14999 s->cset[i] = s->secretcset[ft];
15000 newflag = s->secretflag[ft];
15001 }
15002 else
15003 {
15004 t[j].data[i] = t[j].secretcombo[ft];
15005 t[j].cset[i] = t[j].secretcset[ft];
15006 newflag = t[j].secretflag[ft];
15007 }
15008 }
15009 }
15010
15011 if(newflag >-1)
15012 {
15013 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15014 }
15015 }
15016 }
15017
15018 //if(true)
15019 //{
15020 int32_t newflag = -1;
15021
15022 for(int32_t iter=0; iter<2; ++iter)
15023 {
15024 int32_t checkflag=combobuf[s->data[i]].flag;
15025
15026 if(iter==1)
15027 {
15028 checkflag=s->sflag[i];
15029 }
15030
15031 if((checkflag > 15)&&(checkflag < 32))
15032 {
15033 s->data[i] = s->secretcombo[(checkflag)-16+4];
15034 s->cset[i] = s->secretcset[(checkflag)-16+4];
15035 newflag = s->secretflag[(checkflag)-16+4];
15036 // putit = true;
15037 }
15038 }
15039
15040 if(newflag >-1) s->sflag[i] = newflag;
15041
15042 for(int32_t j=0; j<6; j++)
15043 {
15044 if(!t[j].valid) continue;
15045
15046 int32_t newflag2 = -1;
15047
15048 for(int32_t iter=0; iter<2; ++iter)
15049 {
15050 int32_t checkflag=combobuf[t[j].data[i]].flag;
15051
15052 if(iter==1)
15053 {
15054 checkflag=t[j].sflag[i];
15055 }
15056
15057 if((checkflag > 15)&&(checkflag < 32))
15058 {
15059 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15060 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15061 newflag2 = t[j].secretflag[(checkflag)-16+4];
15062 }
15063 }
15064
15065 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15066 }
15067 }
15068
15069 //FFCs
15070 word num_ffcs = s->numFFC();
15071 for(word i=0; i<num_ffcs; ++i)
15072 {
15073 if(!high16only)
15074 {
15075 for(int32_t iter=0; iter<1; ++iter)
15076 {
15077 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15078
15079 if(iter==1)
15080 {
15081 checkflag=s->sflag[i];
15082 }
15083
15084 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15085 if (ft != -1)
15086 {
15087 s->ffcs[i].data = s->secretcombo[ft];
15088 s->ffcs[i].cset = s->secretcset[ft];
15089 }
15090 }
15091 }
15092
15093 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15094 {
15095 for(int32_t iter=0; iter<1; ++iter)
15096 {
15097 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15098
15099 if(iter==1)
15100 {
15101 // FFCs can't have flags! Yet...
15102 }
15103
15104 if((checkflag > 15)&&(checkflag < 32))
15105 {
15106 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15107 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15108 }
15109 }
15110 }
15111 }
15112 }
15113